Attaching Parsley.js Validation Library to Form Takes Very Long

379 Views Asked by At

I'm trying out the Parsley.js validation library, however, when attaching it to my form (which has several thousand input fields ... it has multiple lists with checkboxes) the Parsley JavaScript runs for almost a minute as it goes through all the fields (even though I've excluded the checkboxes):

<form id="form" data-parsley-validate data-parsley-excluded="input[type=checkbox]">

Is there any setting I could use to fix this problem since excluding the checkboxes doesn't seem to help. Could I just attach the validation to individual fields and not the whole form? If I do that though then I'd have to oversee the form submission, etc. and manually trigger validation, correct?

What's the best approach to take in my situation?

1

There are 1 best solutions below

0
On BEST ANSWER

The issue is that Parsley iterates through all elements that match its input selector, wraps them in a Parsley object (which takes a bit of time), and only then checks if it should be excluded. As you've seen, this is quite slow when dealing with many elements.

To outright ignore checkboxes, you can manually override the inputs configuration option (either directly in JavaScript, or via data-parsley-inputs). The default inputs are input, textarea, select, so all we have to do is make the first one more restrictive:

<form id="form" data-parsley-validate
    data-parsley-inputs="input:not([type='checkbox']), textarea, select">
    <!-- ... -->
</form>

Here's an example fiddle: http://jsfiddle.net/tkt1dvq1/