Dynamic forms

Hi everyone.

Time to time a create dynamic forms.

e.g.

We have country and states (two dropdownslist).

So I want states to be changed when user pick another country. And for some country there is no predefined states, in that case I want to place there textInput.

Obviously javascript can perform this. But I would like to do it on php side only. So when country dropdown is changed, make AJAX request and replace existed form with given one.

To avoid misunderstanding, I do understand how to do it.

But I would like to know if there is something that could help me ? I mean some property for ActiveForm maybe? Or something else?

I ask it because I am positive that I am not the first who run into that problem.

I am considering extending ActiveForm for that purpose, but before that I want to know other opinions.

Any suggestion would be helpfull.

Hi,

Do you mean something like this?

Link: http://demos.krajee.com/widget-details/depdrop

Regards

It could be helpful. But for my purpose that’s to complicated.

All I need is to render form from scratch.

I want to do something like




<?php $form = ActiveForm::begin([

'fieldClass' => 'common\extensions\yiisiv\ActiveField'

]); ?>

//

//

<?= $form->field($model, 'some_attr')->textInput(['maxlength' => true])->affecting(); ?>



I extended ActiveField. And it is works as I expected.

But I want to go further, I want to extened yii\helpers\BaseHtml and want to make framework use my BaseHtml.

Is it real ?