ActiveForm, custom id for field broke validation

Hi everybody,

I’m pretty new with Yii2 and have the next unpleasant issue.

I cretae two forrms at same page like


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

        // make sure you set the id of the form

        'id' => 'create',

        'action' => $action,

        'options' => ['enctype' => 'multipart/form-data']

    ]); ?>


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

        // make sure you set the id of the form

        'id' => 'update',

        'action' => $action,

        'options' => ['enctype' => 'multipart/form-data']

    ]); ?>

I use the same model for both form fields like


            <?=  $form->field($action_model, 'action_name',[

                'addon' => ['prepend' => ['content'=>$action_model->getAttributeLabel('action_mobile')]]

            ])->widget(Typeahead::classname(), [

                'options' => ['placeholder' => $action_model->getAttributeLabel('action_placeholder')],

                    'pluginOptions' => ['highlight'=>true],

                    'dataset' => [

                        [

                        'local' =>  Json::encode( $totalLookUp['action_lookUp'] ),

                        'limit' => 10

                        ]

                    ]

                ])->label(false);

            ?>

And here is the issue. In that case I have two forms with same scope of fields, with same names and same id. What for sure will be not valid for W3C. The another one issue that inspite of that fact that client side presubmit javascript validation for both forms work perfect. The typeahed widget works only for first set of fields since it bindid by id.

If i try to override elements id by specify it by widgets options like


            <?=  $form->field($action_model, 'action_name',[

                'addon' => ['prepend' => ['content'=>$action_model->getAttributeLabel('action_mobile')]]

            ])->widget(Typeahead::classname(), [

                'options' => ['id'=> $form_id.'_action_name',

'placeholder' => $action_model->getAttributeLabel('action_placeholder')],

                    'pluginOptions' => ['highlight'=>true],

                    'dataset' => [

                        [

                        'local' =>  Json::encode( $totalLookUp['action_lookUp'] ),

                        'limit' => 10

                        ]

                    ]

                ])->label(false);

            ?>

the typeahead works perfect, but in that case validation fails, I mean it jsut stop work.

So the questuuion is, how to make posssible adjust validation script and use unique form id’s.

From the docs:


$form->field($action_model, 'action_name', [

    'selectors' => ['input' => '#'.$form_id.'_action_name'],

    'addon' => ...