javascriptjqueryparsley.js

Is it possible to have more than one remote / async validator on an input field in ParsleyJS


In parsleyJS it's possible to create a remote validation with AJAX:

var $email_input = $('#id_email');

// Load validator
$email_input.attr('data-parsley-remote', "");
$email_input.attr('data-parsley-debounce', "1000");
$email_input.attr('data-parsley-remote-validator', "checkexistingcontact");
$email_input.attr('data-parsley-remote-message', "Contact email address already exists.");

window.Parsley.addAsyncValidator('checkexistingcontact', function(xhr) {
         return xhr.status >= 200 && xhr.status < 300;
    },
    '/contacts/validate_contact/?email={value}', { "type": "GET", "dataType": "json" });

It's also possible to include more than one syncronous validator by simply defining them and adding data-parsley-[mySyncrnousValidator] to the input field attr.

However, is it possible to run more than one remote validator? I can't see how to do this, as there does not appear to be a way to set data-parsley-remote-message in the addAsyncValidator function, so any additional async validators would have the same error message?


Solution

  • It wasn't designed like it. It is very easy to add your own custom validator that does an ajax request though.