Multiple inputs with same name are added in a form dynamically using jQuery. So now how can I validate these dynamic inputs using yii2 validation rules at client side ?
-
I have used each validator of Yii2 that will validate all input which have same name but the problem is that it does not validate at client side.It validates after form submission.If one input has error then it shows error under all inputsAsgarAli– AsgarAli2015-06-11 16:02:34 +00:00Commented Jun 11, 2015 at 16:02
-
1Update the question with the code you have and what you just commented so people have all the info they need.Blizz– Blizz2015-06-11 16:03:15 +00:00Commented Jun 11, 2015 at 16:03
-
Please do you have any idea about this dynamic inputs ?Yii2 can't add validation code for dynamic inputs as these are not available at time of form initializationAsgarAli– AsgarAli2015-06-11 16:07:55 +00:00Commented Jun 11, 2015 at 16:07
Add a comment
|
1 Answer
After adding dynamic input using jQuery use below code to validate
jQuery('#form-id').yiiActiveForm("add", {
"id": "input-id",
"name": "input-name",
"container": "#container-id or unique .container-class of this input",
"input": "#input-id or unique .input-class",
"validate": function (attribute, value, messages, deferred, $form) {
yii.validation.required(value, messages, {"message": "Validation Message Here"});
}
}
);
2 Comments
Gaurav Parashar
stackoverflow.com/questions/31286133/…, i am also stuck in the same situation
Gaurav Parashar
how you use the above code can you please elaborate this ali?