Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting ID attribute of input field when using ActiveField in Yii2?

Tags:

php

yii

yii2

I'm trying to set a custom id for an input field whilst using ActiveField in Yii2.

I tried the below, but it instead set the id of the field container instead of the input field itself.

$form->field($model, 'some_id', ['options' => ['id' => 'some_id']])->hiddenInput(['value' => $some_id])->label(false);

Is there a way I can set the id attribute of the input field itself?

I noticed the inputOptions option, but this seems to control the setting for all the fields, so unsure how it works exactly with the selectors etc.

like image 549
Brett Avatar asked Jun 21 '15 08:06

Brett


1 Answers

Just add id key to options array you've already passed in to hiddenInput method

$form->field($model, 'some_id')->hiddenInput(['value' => $some_id, 'id' => 'some_id'])->label(false);
like image 123
Tony Avatar answered Oct 20 '22 12:10

Tony