V
V
Vitaly2017-04-05 14:15:19
Yii
Vitaly, 2017-04-05 14:15:19

Disappears class in ActiveForm?

Good afternoon. There is a form and there is a field

<?= $form->field($model->main, 'alias')->textInput(['maxlength' => true]) ?>

she displays
<div class="form-group field-navigations-alias required">
<label class="control-label col-md-3" for="navigations-alias">Псевдоним</label><div class="col-md-9"><input type="text" id="navigations-alias" name="Navigations[alias]">

<span class="help-block"></span></div>
</div>

But if you set options like this
<?= $form->field($model->main, 'alias', ['options' => ['style' => 'display:none']])->textInput(['maxlength' => true]) ?>

then outputs
<div class="field-navigations-alias required" style="display:none">
<label class="control-label" for="navigations-alias">Псевдоним</label>
<input type="text" id="navigations-alias" class="form-control" name="Navigations[alias]" maxlength="255" aria-required="true">

<div class="help-block"></div>
</div>

That is, when adding options, the form-group class disappears. What could be the problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-04-05
@kat-vetal

If you look at the sources of the ActiveField class (which is actually used when calling the $form->field() method), you will see that the default html options property is written accordingly when you make a call to the field() method in the style
html-options written by default are replaced by the values ​​you passed.
There are two ways to solve this problem:
1. Forcibly set the css class in the required fields, for example
2. Force css-class for all form fields, for example:

$form = ActiveForm::begin([
    'fieldConfig' => [
      'options'=>[
        'class' => 'form-group'
        ]
    ]
]);

A
alex stephen, 2017-04-05
@berezuev

<?= $form->field($model->main, 'alias'])->textInput(['maxlength' => true, 'style' => 'display:none']) ?>

So try

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question