How to prepend / append bootstrap3 icon to Active Form in yii2 alpha

Kshitiz picture Kshitiz · Mar 27, 2014 · Viewed 7.3k times · Source

This is how i added the icon with text field. Also added the image of generated output. I don't want to use Krajee Yii Extensions. So i started to read the documentation.

$form =  \yii\widgets\ActiveForm::begin([
  'id' => 'form-id',
  'options' => ['class' => 'form-horizontal'],
  'enableClientValidation'=> false,
  'enableAjaxValidation'=> true,
  'validateOnSubmit' => true,
  'validateOnChange' => true,
  'validateOnType' => true,
  'action' => 'youraction',
  'validationUrl' => 'yourvalidation'
]);        

    echo $form->field($model, 'fieldname')->begin();
      echo Html::activeLabel($model,'fieldname', ["class"=>"col-sm-3 control-label"]); ?>
      <div class="input-group col-sm-4 ">
        <span class="input-group-addon">
          <span class="glyphicon glyphicon-subtitles"></span>
        </span>
        <?php echo Html::activeTextInput($model, 'fieldname', [
            'class'=>'form-control',
            'autocomplete'=>'off'
          ]
        ); ?>
      </div>
      <?php echo Html::error($model,'origin', ['class' => 'help-block']);
    echo $form->field($model, 'origin')->end();

\yii\widgets\ActiveForm::end(); 

Example View

Answer

Mihai P. picture Mihai P. · Oct 13, 2014

Is this a question or you are showing us how you did it?

You should also be able to do something like:

<?= $form->field($model, 'fieldname', ['template' => '
   <div class="col-sm-2">{label}</div>\n
   <div class="col-sm-10">
       <div class="input-group col-sm-4 ">
          <span class="input-group-addon">
             <span class="glyphicon glyphicon-subtitles"></span>
          </span>
          {input}
       </div>
       {error}{hint}
   </div>'])->textInput(['data-default' => '']) ?>