ExtJS:针对模型的表单验证
我正在学习 ExtJS,并且遇到了两个不同的概念,它们似乎在逻辑上与我相关。
- 模型类可以在其字段上指定自定义验证方法。
- 模型实例可以加载到表单中,也可以从表单中检索。
我的问题是:
- 是否可以让表单使用模型的验证设置来验证用户输入的内容并显示实时反馈?
- 如果1的答案是否定的,那么还有其他方法可以在表单中设置实时验证吗?
谢谢
I'm learning ExtJS, and I came across two different concepts, that seem logically connected to me.
- Model classes can specify custom validation methods on their fields.
- Model instances can be loaded into, and retrieved from Forms.
My question is:
- Is it possible to have the form use the model's validation setup to validate what the user enters and show realtime feedback?
- If the answer to 1 is No, then is there any other way to set up realtime validation in the form?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Molecule Man 所说,没有内置功能,但是...
这似乎成为一个普遍需要的功能(这使得 Ext JS 4 看起来有点不成熟),其他人已经提出了各种解决方案:
第一个建议修改 Ext.form.field.Base 类以允许将表单字段绑定到模型字段,并根据表单字段上定义的验证以及绑定模型上定义的验证来验证表单字段场地。
我正要测试第一个建议,可能会发布有关其进展情况的更新...
As Molecule Man says, there is no built-in functionality for this, however...
This seems to be a commonly required feature (and something that makes Ext JS 4 look a little half-baked), and other people have come up with various solutions:
The first suggestion modifies the Ext.form.field.Base class to allow binding a form field to a Model field, and to validate the form field against validations defined on the form field as well as those defined on the bound Model field.
I'm just about to test the first suggestion, may post an update on how it goes...
没有用于模型实时验证的内置功能。然而,有比使用模型验证更好的方法。
是的,有。
表单字段支持 < code>vtype 配置(更多信息可以在此处)。默认情况下,每次字段值发生更改时都会验证字段(如果您想关闭此行为集字段的
validateOnChange
配置为 false)。查看 文档 (
验证
部分和示例用法
部分)了解更多信息。There is no built-in functionality for model's realtime validating. However, there is better way then using model's validation.
Yes, there is.
Form's fields support
vtype
config (More info can be found here). By default the fields would be validated everytime the fields' value would change (if you want to turn off this behaviour set field'svalidateOnChange
config to false).Check out docs (the
Validation
section and theExample usage
section) for more info.