W
W
WebDeveloper20162016-08-24 09:35:14
Yii
WebDeveloper2016, 2016-08-24 09:35:14

Validation in the generated form?

Form generated with Gii. The form has several checkboxes and an input field. How to make it so that if the field is not empty, and none of the checkboxes are selected, there will be an error. And vice versa, if at least one checkbox is selected, but the field is empty, it is also an error.
P.S. If the tag is not clear, I specify - only Yii 1 !!!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2016-08-24
@slo_nik

https://github.com/yiisoft/yii2/blob/master/docs/g...

A
Alexey, 2016-08-24
@akeinhell

https://habrahabr.ru/post/308298/

M
Maxim Timofeev, 2016-08-26
@webinar

As an option, write your own validator
Or through when:

[[тут атрибуты чекбоксов], 'required', 'when' => function($model) {
        return $model->мой_атрибут_не_пустого_поля == null;
    }],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question