D
D
DarkByte20152018-10-02 10:52:12
Yii
DarkByte2015, 2018-10-02 10:52:12

Required when validation?

There is a model Author(id, lastname, firstname, middlename). I want all fields to be required, but if the model script is editor, then the middlename is optional. I've tried everything - nothing helps. I don't know how to achieve this effect. I even tried to check the validation rules through when, but the problem is that it doesn’t enter the callback, because the rules are already on the client, and not the server does not validate. Ajax validation didn't work either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-10-02
@DarkByte2015

Doesn't it work on the docks ?

[
    // обязательный, указывает, какие атрибуты должны быть проверены по этому правилу.
    // Для одного атрибута, вы можете использовать имя атрибута не создавая массив
    ['attribute1', 'attribute2', ...],

    // обязательный, указывает тип правила.
    // Это может быть имя класса, псевдоним валидатора, или метод для проверки
    'validator',

    // необязательный, указывает, в каком случае(ях) это правило должно применяться
    // если не указан, это означает, что правило применяется ко всем сценариям
    // Вы также можете настроить "except" этот вариант применяет правило ко всем
    // сценариям кроме перечисленных
    'on' => ['scenario1', 'scenario2', ...],

    // необязательный, задает дополнительные конфигурации для объекта validator
    'property1' => 'value1', 'property2' => 'value2', ...
]

in on and list all scenarios?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question