I want to apply required validation on textfield if checkbox is checked otherwise not.i tried by scenario but it's not working, For form i am using 'bootstrap.widgets.TbActiveForm' my Yii version : 1.1.16-dev
Asked
Active
Viewed 628 times
0
-
http://stackoverflow.com/questions/17420129/scenario-for-validation-rules-in-yii/17420594#17420594 – ineersa May 15 '16 at 11:16
-
Thanks ineersa, but that worked after page get submitted, it validate fields and don't allow to save. it should validate clientside like other required field – Ratnadip Khandekar May 17 '16 at 05:33
1 Answers
0
In model Rule section
[['textfield'], 'required', 'when' => function ($model) {
return $model->chechboxStatus == '1';
}, 'whenClient' => "function (attribute, value) {
return $('#demo-chechboxstatus').prop('checked') == true;
}"],
or if you using any scenario then you can use like this
[['textfield'], 'required', 'when' => function ($model) {
return $model->chechboxStatus == '1';
}, 'whenClient' => "function (attribute, value) {
return $('#demo-chechboxstatus').prop('checked') == true;
}",'on'=>'create'],

SAR
- 57
- 8