Answer the question
In order to leave comments, you need to log in
Yii2 how to dynamically add validated fields?
Good afternoon,
I want to make a Button + and - when you click on it, the field is added and the page is not reloaded.
Can you suggest how to do it? Maybe someone did and there is a solution :-)
Answer the question
In order to leave comments, you need to log in
Ajax, so as not to be smart with layout in js and overriding validation methods on the client.
In Yii1, I did just that.
You can create an array of values and write your own validator.
to the model
public function rules() {
return [
...
['fields', 'validateFields'],
...
];
}
public function validateFields() {
for ($i = 0; $i < count($this->fields); ++$i) {
...
}
}
<?php $form->field($model, 'fields[]') ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question