验证预填充的 jQuery 表单(第一个字段清除时无效,ASP.NET 且不显眼)
我有一个可以填写、保存、加载和重新编辑的表格。
当它被加载并重新编辑时,它可能开始有效。 当一个字段在加载时有效时,我希望它在违反规则的编辑时立即无效。简而言之,这是我的问题,我怀疑这是由某些我无法支持的配置选项支持的寻找。
目前,只有在以下情况下它才能正常工作(按照上面所需的方式):1)对其进行编辑,2)然后该字段在有效时失去焦点,3)然后再次对其进行编辑。因此,需要额外有效地失去焦点才能可视化预填写表格的错误。
如果加载时它为空(例如第一次访问),则不应显示错误。
我已经在我的框架中使用以下内容:
- jQuery.validate (“已批准”的,也是我问题的焦点)
- ASP.NET MVC 3 的 jQuery 非侵入性验证适配器
我当前不运行任何自定义代码 激活此功能,因为“不引人注目”适配器会初始化验证(但我很乐意修复此问题)。我尝试在页面加载时添加“form.valid()”,但它不能解决上述问题,实际上会破坏更多的东西。
谢谢, 香农
I have a form that can be filled, saved, loaded and re-edited.
When it is loaded and re-edited, it probably begins its life valid. When a field is valid upon load, I want it to invalidate immediately when it is edited contrary to rules. That's my question in a nutshell, and I suspect this is supported by some configuration option I can't find.
Currently, it works properly (the way desired above) only after: 1) it is edited, 2) then the field loses focus while valid, 3) then is edited it again. So it takes an extra valid loss of focus to visualize errors for a pre-filled form.
If it is empty on load (such as the first visit) it should not show errors.
I'm using the following already in my framework:
- jQuery.validate (the 'approved' one, and the focus of my question)
- jQuery unobtrusive validation adapter for ASP.NET MVC 3
I don't currently run any custom code to activate this, since the 'unobtrusive' adapter initializes validation (but I'd be happy to, to fix this). I've tried adding 'form.valid()' on page load, but it doesn't fix the above and in fact breaks more stuff.
Thanks,
Shannon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我深入研究了验证插件,并针对我认为存在缺陷的问题开具了一张票。
https://github.com/jzaefferer/jquery-validation/issues/146
香农
I've dug into the validation plug-in, and opened a ticket for what I believe is a defect.
https://github.com/jzaefferer/jquery-validation/issues/146
Shannon
您可以尝试在每次更改输入时手动验证表单。
从查看文档看来,如果不先调用
form.validate();
,就无法调用form.valid()
。You could try validating the form manually each time an input was changed.
From looking at the documentation it seems that you can't call
form.valid()
without callingform.validate();
first.这个构造函数对我有用:
This constructor works for me: