ActiveForm - add dynamically field and validators


does anyone know how to add into Yii2 ActiveForm dynamically new field, so the field would be registered into ActiveForm including client side validators?


I have a wizard, which consists of 5 steps.

Next step loads via ajax (renderAjax) and inserts inside of existing ActiveForm piece of HTML code.

The problem is, that new elements won’t register into ActiveForm, so client validation and errors won’t work.

It’s just inserted dead HTML code, no ActiveForm magic:-(

The issue:

Thanx for any advices.

There isn’t much detail here, but have you considered creating 5 forms, one for each step, and validating on moving between steps?

Your solution actually works - it binds correctly client side validators, which is great.

However, it brings up another problems, e.g. how to validate all forms in one shot or prevent submitting 3. form if there is error on form 2 (we have of course only 1 submit button for all steps).