samedi 21 mars 2015

parsley.js: Dynamically add validation to form via javascript

I´m stuck. I can´t edit the html for the form, so i need to add parsley.js validation attributes after page load, but parsley doesn´t seem to run if i use it like this:



var myForm = "#theForm";
jQuery( document ).ready(function() {
if (jQuery(myForm).length) {

jQuery( '#user_email' ).attr( 'data-parsley-equalto', '#user_email_validate');

jQuery( myForm ).parsley();
}
});


Exchanging the validation line with the following works fine, so it seems to be a problem with the 'data-parsley-XXX' part:



jQuery( '#last_name' ).attr( 'minlength', 2);


What am i missing? Thanks a lot.


Aucun commentaire:

Enregistrer un commentaire