我正在使用带有验证规则的动态表单,我想让浏览器在提交之前也验证表单,所以我使用了whenClient
. 有一个复选框,单击时不会处理验证...
['dv_number', 'required', 'when' => function ($model) {
return $model->is_cancelled == 1;
}, 'whenClient' => "function (attribute, value) {
console.log(attribute.name);
var firstletter=(attribute.name.charAt(0));
var index='';
if(firstletter==='['){ //when dynamic form is not activated and name of inputs is like [0]dv_number
index=attribute.name.charAt(1);//I get the array index
}else{
index=attribute.name.charAt(9);//dynamic form activated the name of inputs changed like this TblDvBub[0][dv_number].
}
if($('[name=\'TblDvBub[0][is_cancelled][]\']').is(\":checked\"))
{
return false;//validation will not take place
}
else
{
return true;//validation from browser takes place
}
}"
],
所以我使用index
变量获取索引号。我的问题是替换0
这一行if($('[name=\'TblDvBub[0][is_cancelled][]\']').is(\":checked\"))
中的索引并使其像这样if($('[name=\'TblDvBub[index][is_cancelled][]\']').is(\":checked\"))
请注意,从客户端被" "
...包围时开始的整个代码
我已经尝试过这个和很多其他的,但无济于事。
if($('[name=\'TblDvBub[' + index +'][is_cancelled][]\']').is(\":checked\"))