user2191247
user2191247

Reputation:

Providing custom validation message

We have a form with fields loaded from a model. For a currency field, the client wants a specific error message for values less than the minimum value or greater than the maximum value.

It is easy to set the minimum and maximum values using setMinValue and setMaxValue, say in onAfterRender, but there doesn't appear to be a way to set the error message.

There is a setActiveError call, but I'm not sure how to hook it in. Is it possible to provide a custom form validation?

We have access to the data model definition, so we could add a validator, but a complication is that it isn't always the case that this validation is required.

We also have access to initComponent for the form, but note the form is loaded from a model, so no config.

Upvotes: 0

Views: 42

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30082

They are configurable using a template, see minText & maxText here: http://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.form.field.Number-cfg-minText

Something like:

initComponent: function() {
    this.minText = 'Not enough! More than ${0} ok?';
    this.maxText = 'Too much! Less than ${0}';
    this.callParent();
}

Upvotes: 1

Related Questions