简体   繁体   English

提供自定义验证消息

[英]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. 使用setMinValuesetMaxValue设置最小值和最大值很容易,例如在onAfterRender ,但是似乎没有设置错误消息的方法。

There is a setActiveError call, but I'm not sure how to hook it in. Is it possible to provide a custom form validation? 有一个setActiveError调用,但是我不确定如何将其挂接。是否可以提供自定义表单验证?

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. 我们可以访问数据模型定义,因此我们可以添加一个validator ,但麻烦的是,并不一定总是需要此验证。

We also have access to initComponent for the form, but note the form is loaded from a model, so no config . 我们还可以访问该表单的initComponent ,但是请注意,该表单是从模型加载的,因此没有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 它们可以使用模板进行配置,请参见此处的minText和maxText: 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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