i have two forms holds the same model attributes, since Yii2 generate the field id to be ModelName-fieldName so the field generated will be as follow:
<select name="Channel[channel]" class="form-control" id="channel-description">
i have tried to use fieldConfig in Activeform but it doesn't add the id to the field itself.
You should simply use the third parameter of ActiveForm::field()
:
$options
: The additional configurations for the field object.
e.g. :
$form->field($model, 'channel', ['inputOptions' => ['id' => 'channel-description']])
Read more about ActiveForm::field().
But if you really want to add a prefix to all your fields ids, you should override ActiveForm
.
If you want save input id structure "{model}-{attribute}".
Use yii\helpers\Html::getInputId() for generate "{model}-{attribute}" input id and complete it with your custom prefix.
$form->field($model, 'name')->textInput(['id' => 'custom-' . Html::getInputId($model, 'name')])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With