admin管理员组文章数量:1323714
I'm using Parsley.js to validate my form. I tell Parsley to monitor the form by adding...
<form data-validate="parsley" name="myform">
And my elements look like:
<input type="text" name="username" data-required="true"/>
If you neglect the required fields and attempt to submit the form using this button...
<input type="submit" value="Submit"/>
Parsley displays an error and does not allow the form to be submitted. However, if you use the following submit method instead...
<a href="#" onClick="document.myform.submit();"> Submit </a>
Parlsey simply ignores the errors and submits the form. What is going on? Is Parsley listening specifically to the input[type=submit] element rather than the submission of the form itself? (I need to make the "Submit" feature a link because I want to apply special styles to it.)
I'm using Parsley.js to validate my form. I tell Parsley to monitor the form by adding...
<form data-validate="parsley" name="myform">
And my elements look like:
<input type="text" name="username" data-required="true"/>
If you neglect the required fields and attempt to submit the form using this button...
<input type="submit" value="Submit"/>
Parsley displays an error and does not allow the form to be submitted. However, if you use the following submit method instead...
<a href="#" onClick="document.myform.submit();"> Submit </a>
Parlsey simply ignores the errors and submits the form. What is going on? Is Parsley listening specifically to the input[type=submit] element rather than the submission of the form itself? (I need to make the "Submit" feature a link because I want to apply special styles to it.)
Share Improve this question asked Nov 6, 2013 at 20:17 hawkharrishawkharris 2,6506 gold badges26 silver badges37 bronze badges2 Answers
Reset to default 5I'm not sure how parsley figures that it needs to validate, but you can always trigger validation yourself with document.myform.parsley( 'validate' );
, so in your case you'd have to do:
if (document.myform.parsley( 'validate' ))
{document.myform.submit();}
I would expect Parsley to have a on submit handler automatically, but until I find out from the source you can do this:
$('form#my-form').on "submit", (e)->
$(this).parsley().validate()
Note that this is coffeescript. JS would be
$('form#my-form').on("submit", function(e) {
return $(this).parsley().validate();
});
Of course all your inputs have to have the data attributes set such as:
data-parsley-required="true"
本文标签: javascriptParsleyjs validation not triggeringStack Overflow
版权声明:本文标题:javascript - Parsley.js validation not triggering - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742126373a2421961.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论