Why is checkbox validation not working in Parsley.js?

I can't for the rest of my life get Parsley.js to validate my checkboxes, although my code looks the same as their example. My HTML looks like this:

<div class='button-row'>
  <input data-parsley-mincheck='1' id='add-package-a-pre' name='add-package-alerts' type='checkbox' value='pre'>
  <label for='add-package-a-pre'>
    Pakke registrert
  </label>
  <input id='add-package-a-sent' name='add-package-alerts' type='checkbox' value='sent'>
  <label for='add-package-a-sent'>
    Pakke sendt
  </label>
  <input id='add-package-a-ready' name='add-package-alerts' type='checkbox' value='ready'>
  <label for='add-package-a-ready'>
    Pakke klar for henting
  </label>
  <input id='add-package-a-loaded' name='add-package-alerts' type='checkbox' value='loaded'>
  <label for='add-package-a-loaded'>
    Pakke lastet opp for utkjøring
  </label>
  <input id='add-package-a-delivered' name='add-package-alerts' type='checkbox' value='delivered'>
  <label for='add-package-a-delivered'>
    Pakke leveret
  </label>
</div>

      

Parsley works out of the box and prevents my form from submitting when I have an error in one of my text inputs, but it completely ignores the fact that none of my checkboxes are checked. As far as I can tell my code looks the same as in the example they provide: http://parsleyjs.org/doc/examples/simple.html

I also created a JSFiddle that demonstrates the problem.

Can anyone understand why it is not working? I have been stuck on this for hours and I cannot find anyone else experiencing the same problem.

+3


source to share


1 answer


It turns out that Parsley will always assume that the checkboxes are unchecked if the attribute is required

not set, even if it data-parsley-checkmin="1"

is.

Develop:



  • <input type="checkbox" data-parsley-checkmin="1" />


    Will always pass the test, no matter what
  • <input type="checkbox" data-parsley-checkmin="2" />


    Will be checked only with an error if checkbox 1 is selected.
  • <input type="checkbox" data-parsley-checkmin="1" required />


    Validation failed if checkboxes are not checked.

In other words, it is data-parsley-checkmin="1"

never useful. Just replace it with required

.

+8


source







All Articles