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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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"});
}
}
);