Yii2 client side validation for dynamically added

2019-07-11 05:21发布

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 ?

标签: yii2
1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-11 06:12

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"});
        }
    }
);
查看更多
登录 后发表回答