我想在textfield上应用必要的验证,如果选中复选框,否则不会。我尝试了方案,但它不起作用,对于表单,我正在使用'bootstrap.widgets.TbActiveForm' 我的Yii版本:1.1.16-dev
答案 0 :(得分:0)
在模型规则部分
[['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'],