yii2 表单验证不起作用 [英] yii2 form validation not working
本文介绍了yii2 表单验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何知道在 yii2 活动表单中是否触发了验证?我正在使用
How to know if the validation has been triggered in yii2 active form? I am using
$('#formId').yiiActiveForm('validate', true);
验证表单,但它总是返回 undefined.
to validate the form, but it always returns undefined.
推荐答案
触发表单验证试试这个:
Trigger the form validation try this :
var $form = $("#formId"),
data = $form.data("yiiActiveForm");
$.each(data.attributes, function() {
this.status = 3;
});
$form.yiiActiveForm("validate");
我创建了一个函数来验证javascript中的活动表单,它将返回true/false.也许有用:
I've create a function to validating active form in javascript, it will be return true/false. Maybe usefull :
function checkForm(form_id){
var $form = $("#"+form_id), data = $form.data("yiiActiveForm");
$.each(data.attributes, function() {
this.status = 3;
});
$form.yiiActiveForm("validate");
if ($form.find('.has-error').length == 0) {
return true;
}
return false;
}
称之为:
checkForm("formId"); // it will be return true/false and also validating the form
这篇关于yii2 表单验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文