简体   繁体   中英

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 .

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM