Answer the question
In order to leave comments, you need to log in
How to validate dynamically added form fields in YII2?
Hello everyone, the subject
itself There is ActiveForm, there is a form validation class
In the validation class all known form attributes and rules for them are registered
And how to make validation of dynamically added form fields?
Well, that is, to do so, so to speak, validation not by the field (name), but, so to speak, by some attribute of it (I don’t know the class) ...
That is, for example, there is one tariff in the form (price list position)
It consists of ID , names and prices
I can register in the validator (for example)
.......
[
['id', 'name', 'price'],
'required',
'message' => 'Укажите значение',
],
[
['price'],
'integer',
'message' => 'Укажите целое число',
],
[
['name'],
'string',
'max' => 250,
],
.......
.......
[
['patern_id', 'patern_name', 'patern_price'],
'required',
'message' => 'Укажите значение',
],
[
['patern_price'],
'integer',
'message' => 'Укажите целое число',
],
[
['patern_name'],
'string',
'max' => 250,
],
.......
Answer the question
In order to leave comments, you need to log in
"I do not read the documentation, I write as I want."?
www.yiiframework.com/doc-2.0/guide-input-tabular-i...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question