Reputation: 7540
In parsley2, is there no way to disable validation for a field? i.e. I have a <select>
-control, which will always return a value and needs to further validation. Parsley's unneeded error-list, however, ruins my formatting - so I'd like to disable validation complately for that field. I know I could assign a different error-container, but that feels 'unclean'...
I tried to add data-parsley-exclude="select"
to the form, but that has no effect. (It was a wild guess anyway...)
Upvotes: 2
Views: 13046
Reputation: 432
For Parsley V2 -- add data-parsley-excluded=true
to your element.
REF: https://parsleyjs.org/doc/
Upvotes: 0
Reputation: 533
I know this old, but I actually still use Parsley v1 and I typically use the
$('#form').parsley('validate')
...command to validate a form in a custom way.
I needed to exclude a field that has its own custom validation and I used Parsley's removeItem
call right before I called the above command. This removes the field from the validation cycle:
$('#form').parsley('removeItem', '#someInput');
Upvotes: 0
Reputation: 7448
You can:
You could think for a more "clean" exclusion method and submit it in a PR.
Best
Upvotes: 0
Reputation: 5174
I've found some issues with this method that I'm still trying to fix, so your mileage may vary with what I'm about to show you.
You can deactivate parsley validation, remove the required
attribute for the element that you want to disable validation for, and then reactivate Parsley.
First, let's assume you bound Parsley validation to your form like so:
$('#my-form').parsley({
//options
});
The element #my-reg-form
is your <form>
, just to be clear.
Your "refresh" of Parsley validation code would look something like:
// Deactivate Parsley validation
$('#my-form').parsley().destroy();
// Make your field not required, thus disabling validation for it
$('#disabled-select').removeAttr('required');
// Reactivate Parsley validation
$('#my-form').parsley({
//options
});
This can also be done in reverse, if you want to make that field a required field again.
// Deactivate Parsley validation
$('#my-form').parsley().destroy();
// Make your field required by adding the required attribute back to the element
$('#disabled-select').attr('required', '');
// Reactivate Parsley validation
$('#my-form').parsley({
//options
});
Upvotes: 3