Question

When I try to submit a form, either via an input[type=submit] or by calling form.submit(), Parsley validates the form and cancels the submission if invalid. Is there any way I can skip that validation since I'm manually calling validate on sections of my form?

Specifically what I'm trying to achieve is submitting partial versions of the form, so I validate a group and only that portion is sent to the server (even if the rest of the form is still not valid).

Était-ce utile?

La solution

I you want to cancel Parsley default validation on submit event, you'll have to remove the submit.Parsley binded event on your form.

Doing a $('#yourform').off('submit.Parsley'); should solve your issue.

Best

Edit: For Parsley2, since events names have changed, it should be $('#yourform').off('form:validate');

Autres conseils

if you want to skip single element just use :

data-parsley-excluded

Form fields that won't be validated by Parsley. For example, if you want to add disabled and hidden fields to the existing list, use: data-parsley-excluded="input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :hidden"

but if you want to validate a specific groupd then use:

data-parsley-group

Assign a group to a field for specific group validation. eg: data-parsley-group="signup". This way, you could only validate a portion of a form and not all the fields.

source :

http://parsleyjs.org/doc/index.html#psly-usage-form

When running the submit in JS you can do:

$('#yourform').parsley().destroy();

So with jQuery in code, it could look like this:

var $myForm = $('#yourform');

$("#submit-button").on('click',function(e){
  e.preventDefault();
  
  $myForm.parsley().destroy();
  $myForm.submit();
});

As I answered here, adding formnovalidate to the button seems to work https://stackoverflow.com/a/74746624/1148163

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