I was working on Yii2 and would like to dynamically validate the field, like validate if another field is not selected.
I found below code on Yii2 documentation:
['state', 'required', 'when' => function($model) {
return $model->country == 'USA';
}]
But the thing is that I am using Yii2 dynamic model. How could I achieve the same thing shown above in dynamic model.
addRuleon the dynamic model like,$model->addRule(['field_name','string',['max'=>255]]), and then call the validate$model->validate(), this will call the validation and show you the errors, you need to show the code. you are working on.