简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM