Since I needed to approach this goal I have tried different solution and came up with an ideal solution which I would like to share here since no one yet could answer this question. The solution is for both radionList
and checkboxList
.
Just inject the $arrayOption
with the following code snippet.
$arrayOption[0] = 'Others <input type="text" class="my-class-name" name="MyModel[my_other_option]">';
Add the following code into the rules
function inside of the model
class.
[
['my_other_option',], 'required' , 'when' => function($model) {
return $model->choises == '0';
},
],
By doing so, the validation will be failed when you selected the Other
option but didn't fill in the input text field, named my_other_option
.