M
M
Mikha Pankratov2015-04-06 17:19:22
Yii
Mikha Pankratov, 2015-04-06 17:19:22

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

2 answer(s)
E
Evgeny Dozhdikov, 2015-04-06
@frmax

Ajax, so as not to be smart with layout in js and overriding validation methods on the client.
In Yii1, I did just that.

S
Sergey Semenko, 2015-04-06
@abler98

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) {
    ...
  }
}

In the shape of
<?php $form->field($model, 'fields[]') ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question