Question

I have a form I'm validating using Parsley.js that was working before, but now won't allow submission of the form, though there's no explanation of why form submission is failing (though I've verified it's Parsley that's preventing submission). Two questions:

(1) I suspect that Parsley validations are failing on a field that's hidden or just not displaying its error messages for some reason. Is there a way to just log all the Parsley validation failures in the console?

(2) Is there a way to disable Parsley from preventing form submission, while still keeping alive Parsley's features for providing "live" validation feedback on keypress, etc.?


The code:

Here's a sample input div with the parsley validation info, as it's being rendered:

<input class="parsley-validated parsley-error" data-parsley-required="true" data-parsley-trigger="keyup change keypress" id="order_delivery_address" name="order[delivery_address]" placeholder="Address" type="text" value="" data-parsley-id="8942">

I initialize Parsley like this:

$('#new_order').parsley()
Était-ce utile?

La solution

1) Parsley fields results are stored in validationResult, for each field. Fields are stored in fields.

var failingFields = [],
  parsleyForm = $('#new_order').parsley();

for (var i = 0; i < parsleyForm.fields.length; i++)
  if (true !== parsleyForm.fields[i].validationResult && parsleyForm.fields[i].validationResult.length)
    failingFields.push(parsleyForm.fields[i].$element);

2) To prevent Parsley from preventing form submission, you'd have to do $('#new_order).off('submit.Parsley')

Autres conseils

Code would be helpful, but to elaborate on part 2 you can do this..

$('form').off('submit.parsleyForm');

... after the $('form').parsley(...) initialisation call.

Just make sure you call $('form').parsley('validate') when you want to validate the form.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top