jQuery Validate Plugin - 触发单个字段的验证
我有一个可以选择通过 facebook connect 预先填充的表格。用户连接后,他们的姓名和电子邮件会自动填写。问题是,这不会触发远程验证来检查电子邮件是否已存在。
有没有办法可以单独调用该字段的验证?像这样的东西:
$('#email-field-only').validate()
是个好主意。搜索了文档但没有运气。
I've got a form that can optionally be pre-populated via facebook connect. Once a user connects, their name and email are automatically filled in. The problem is that this doesn't trigger the remote validation to check if the email already exists.
Is there a way I could call the validation on that field alone? Something like:
$('#email-field-only').validate()
would be idea. Searched through the docs with no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
此方法似乎可以满足您的要求:
编辑
API 已更改,请参阅 Paul 的回答。
This method seems to do what you want:
Edit
API has changed, see Paul's answer.
使用
Validator.element()
:下面是 API 中显示的示例:
.valid()
验证整个表单,正如其他人指出的那样出去。 API 说:Use
Validator.element()
:Here is the example shown in the API:
.valid()
validates the entire form, as others have pointed out. The API says:由于某种原因,一些其他方法在字段被聚焦/模糊/更改或尝试提交之前不起作用......这对我有用。
必须深入研究 jquery.validate 脚本才能找到它......
For some reason, some of the other methods don't work until the field has been focused/blured/changed, or a submit has been attempted... this works for me.
Had to dig through the jquery.validate script to find it...
如果您想验证单个表单字段,但不希望触发 UI 并显示任何验证错误,您可以考虑使用 Validator.check() 方法,该方法将返回给定字段是否通过验证。
这是例子
If you want to validate individual form field, but don't want for UI to be triggered and display any validation errors, you may consider to use Validator.check() method which returns if given field passes validation or not.
Here is example
当您设置验证时,您应该保存验证器对象。您可以使用它来验证各个字段。
-- 与 这个类似的问题
When you set up your validation, you should be saving the validator object. you can use this to validate individual fields.
-- cross posted with this similar question
如果您想对表单上的“某些元素”(不是所有元素)进行验证。您可以使用此方法:
希望它对大家有帮助:)
已编辑
in case u wanna do the validation for "some elements" (not all element) on your form.You can use this method:
Hope it help everybody :)
EDITED
我遇到了几乎相同的问题,但对于我的情况,我只需要验证 4 个字段。
这就是我所做的;我向我想要验证的元素添加了一个类。然后我在该特定类上调用了 validate() 。
I had almost the same issue but for my case, I needed to validate just 4 fields.
This is what I did; I added a class to the elements I wanted to validate. Then I called the
validate()
on that specific class.