Answer the question
In order to leave comments, you need to log in
How to make one of the checkboxes mandatory Yii2?
Good day! I have 5 fields with checkbox type. How can I do it in Yii2 so that if at least one of them was filled, then the validation is successful, otherwise, say that select at least one checkbox. Thanks in advance!
Answer the question
In order to leave comments, you need to log in
www.yiiframework.com/doc-2.0/yii-validators-valid...
[['check1','check2','check3'],'required','when'=>function ($model) {
return ($model->check1 == null and $model->check2 == null and $model->check3 == null);
}, 'message'=>'чудак, чекни хоть что-нибудь']
write a validation javascript: check the values of all checkboxes and if everything is not
checkd, then show an error message
Change checkbox to radio and make it required
$form->field($model, 'radioAttribute')
->radioList([
'1' => 'Первый',
'2' => 'Второй',
'3' => 'Третий'
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question