admin管理员组文章数量:1186428
Do we have any function which returns all the error messages while validating a form?
I have tried using the defaultshowerros() function but it returns the error message for the element it is currently validating. How can I get all the error messages of the whole form?
Do we have any function which returns all the error messages while validating a form?
I have tried using the defaultshowerros() function but it returns the error message for the element it is currently validating. How can I get all the error messages of the whole form?
Share Improve this question edited Sep 28, 2010 at 10:06 Nick Craver 630k138 gold badges1.3k silver badges1.2k bronze badges asked Sep 28, 2010 at 8:42 Vaibhav JainVaibhav Jain 34.4k47 gold badges115 silver badges165 bronze badges 2- could you provide a link to the validation plugin you are using? Or even better some source code :) – Flatlin3 Commented Sep 28, 2010 at 8:47
- I am using this plugin docs.jquery.com/Plugins/Validation – Vaibhav Jain Commented Sep 28, 2010 at 8:49
3 Answers
Reset to default 23If you store a reference to the validator, for example:
var validator = $("form").validate();
You can call .errors()
or .invalidElements()
at any time on it, for example:
var errors = validator.errors(); //get the error elements, the actual labels
var errors = validator.invalidElements(); //the invalid elements themselves
If you're not really after the errors and just want them to appear in once place, use the built-in errorLabelContainer
and wrapper
options, for example:
<ul id="errors"></ul>
And reference that:
$("form").validate({ errorLabelContainer: "#errors", wrapper: "li" });
And your errors would appear all in that list, which is also automatically shown/hidden if there are/aren't any errors.
The validation plugin should show an error beside the field where the error is. Are you using id's for your input boxes? If so use a name as well and give jquery the value of the name attribute in your rules and messages. Hope this helps.
Late to the party, but I found you can also instantiate the validate()
object with a invalidHandler()
function:
var $jqvForm = $(".jqvForm").validate({
invalidHandler: function(e, validation){
console.log("invalidHandler : event", e);
console.log("invalidHandler : validation", validation);
}
});
The validation
variable contains a variable invalid
(object) with form items and their error messages.
本文标签: javascriptHow can I show errors in jQuery validationStack Overflow
版权声明:本文标题:javascript - How can I show errors in jQuery validation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738358047a2080206.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论