Answer the question
In order to leave comments, you need to log in
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
Use whenClient
for 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 questionAsk a Question
731 491 924 answers to any question