Bharat Soni
Bharat Soni

Reputation: 2902

How to add Validation constraints dynamically in parsley js

Hi I'm validating few fields in form and using parsley.js for that, There are few situations where I have to add validation constraints dynamically using JS but Parsley is not accepting it. Please Have a look at code and correct me :

JS(All of what I have tried):

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

$('#customerAccount').parsley('addConstraint', {'length' : '[10,10]' }); //This is one way I tried

$('#customerAccount').attr({'length' : '[10,10]' }); //This is another way I tried

$('#billForm').parsley();

Let me know if you need anything else.

Upvotes: 0

Views: 790

Answers (1)

Luís Cruz
Luís Cruz

Reputation: 14970

You need to set the correct attribute (which is data-parsley-length if you're using Parsley 2.x).:

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

$('#customerAccount').attr('data-parsley-length', '[10, 10]');

$('#billForm').parsley();

Upvotes: 1

Related Questions