Use parsley.js for certain areas of a form?

2019-02-26 00:51发布

I'm using parsley.js (parsleyjs.org) in combination with acc-wizard.js (http://sathomas.me/acc-wizard/).

Is there a way to make parsley check only a certain region (see following code, e.g. region one, which could contain 5 input fields) instead of the whole form?

<form>
    <div id="one">fields for parsley.js to validate...</div>
    <div id="two">fields for parsley.js to validate...</div>
    <div id="three">fields for parsley.js to validate...</div>
</form>

Thanks!

2条回答
成全新的幸福
2楼-- · 2019-02-26 01:04

Good news, Parsley2 now have a group option that allows to define different areas on a form and validate them separately :)

Tadaa: http://parsleyjs.org/doc/examples/multisteps.html

查看更多
来,给爷笑一个
3楼-- · 2019-02-26 01:22

You can initiate Parsley via JavaScript so that you can pass in custom options. Then you can just use the excluded param to remove whichever sections of the form you don't wish to validate.

http://jsfiddle.net/5JA8R/

$('form').parsley({
    excluded: '.two input, .three input'
});
查看更多
登录 后发表回答