R
R
Ruslan Dzh2019-05-08 13:55:25
Yii
Ruslan Dzh, 2019-05-08 13:55:25

How to place fields in yii2?

Good day!
I can not figure out how to place the columns in the required sequence.
It is necessary that it looks like this:
5cd2b4ed0245e589872414.png
But I have everything in one column, I try this:

<?php $form = ActiveForm::begin([
  'id' => 'save-form',
  'layout' => 'horizontal',
  'fieldConfig' => [
      'template' => "{label}\n
                      <div class=\"col-lg-4\">
                        {input}
                      </div>\n
                    ",
      'labelOptions' => ['class' => 'col-lg-2 control-label'],  
  ],    
]); ?>

<?= $form->field($model, 'type')->textInput() ?>
<?= $form->field($model, 'number')->textInput() ?>
<?= $form->field($model, 'region')->textInput(['maxlength' => true]) ?>

If in template I do this
'template' => "{label}\n
                      <div class=\"col-lg-4\">
                        {input}
                      </div>\n
{label}\n
                      <div class=\"col-lg-4\">
                        {input}
                      </div>\n
                    ",

That records are displayed in two columns, but are duplicated.
Help me to understand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-05-09
@rdzh

Good morning.
The simplest and most effective option

<div class="col-lg-6">
   <?= $form->field($model, 'type')->textInput() ?>
   <?= $form->field($model, 'number')->textInput() ?>
   <?= $form->field($model, 'region')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-lg-6">
   <?= $form->field($model, 'type')->textInput() ?>
   <?= $form->field($model, 'number')->textInput() ?>
   <?= $form->field($model, 'region')->textInput(['maxlength' => true]) ?>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question