Validate Chosen Multi Selection with Parsley.js

2019-09-11 00:34发布

I managed to get parsleyjs.org validate a "required" Chosen dropdown but I can't seem to be able to validate the Multi selection dropdown.

I have tried to apply the max and min validation rules, that did not work.

I have setup parsleyjs.org and Choosen on a test site here: http://loai.directory/test/test/blank.php

How can I validate min and max on a multi selection dropdwon with parsleyjs?

1条回答
Ridiculous、
2楼-- · 2019-09-11 00:58

You should use data-parsley-mincheck for that. The following example works as expected (jsfiddle demo).

<form id="myForm">
    <select name="[]" multiple="multiple" data-parsley-required data-parsley-mincheck="2">
        <optgroup label="Section">
            <option>Drop Down Option A</option>
            <option>Drop Down Option B</option>
        </optgroup>
        <optgroup label="Section">
            <option>Drop Down Option A</option>
            <option>Drop Down Option B</option>
        </optgroup>
    </select>

    <input type="submit" />
</form>

<script>
$(document).ready(function() {
    $("select").chosen();

    $("#myForm").parsley();
});
</script>
查看更多
登录 后发表回答