如果复选框被选中,我想对文本字段应用所需的验证,否则就不应用了。我尝试过场景,但它不起作用,对于表单,我使用的是'bootstrap.widgets.TbActiveForm'我的Yii版本:1.1.16-dev
在模型规则部分
[['textfield'], 'required', 'when' => function ($model) {
return $model->chechboxStatus == '1';
}, 'whenClient' => "function (attribute, value) {
return $('#demo-chechboxstatus').prop('checked') == true;
}"],
或者如果你使用任何场景,那么你可以像这样使用
[['textfield'], 'required', 'when' => function ($model) {
return $model->chechboxStatus == '1';
}, 'whenClient' => "function (attribute, value) {
return $('#demo-chechboxstatus').prop('checked') == true;
}",'on'=>'create'],