E
E
Eugene2015-02-11 13:20:14
JavaScript
Eugene, 2015-02-11 13:20:14

Yii2: How to do conditional js validation of two related models?

Hello,
There are two models Company (id, title, hasEmployee) and Employee (id, name, companyId) filled on the same form. Whether the employee is filled in or not depends on the hasEmployee field. And if everything is clear with the usual validation in the model, then what to do with client-side validation (simple js, without ajax)? How to make the standard validators run depending on the condition?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shulgin, 2015-02-19
@6pblcb

Use whenClientfor attributes of the second model (Employee).
https://github.com/yiisoft/yii2/blob/master/docs/g...
www.yiiframework.com/doc-2.0/yii-validators-valida...
https://github.com/yiisoft/ yii2/blob/master/framew...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question