如果复选框被选中,则设置 Yii 场景

Set Yii Scenario if checkbox is checked

如果复选框被选中,我想在文本字段上应用必需的验证,否则 not.i 场景尝试但它不起作用,对于我正在使用的表单 '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'],