I am trying to use this validation rule in my model, but it's not working.
I mean it always remains safe even if select other option.
[['dhanwantri_bill_number'], 'safe',
'when' => function($model) {
return $model->bill_type =='d';
},
'whenClient' => "function (attribute, value) {
return $('#opdtestbill-bill_type').val() == 'd';
}"
],
Am I doing anything wrong? is there any alternative solution to achieve the same.
Thanks.
Rule for bill_type is like
[['bill_type'], 'string', 'max' => 20],
[['bill_type','test_name','date'], 'required'],
Edit safe attribute public properties as per doc
$when - callable - A PHP callable whose return value determines whether this validator should be applied. yii\validators\Validator
$whenClient - string - A JavaScript function name whose return value determines whether this validator should be applied on the client side. yii\validators\Validator
dhanwantri_bill_numberif bill_type is 'd' and disallow in other cases. - Pawan