2014-03-27 51 views
4

這就是我添加帶有文本字段的圖標的方式。還添加了生成輸出的圖像。 我不想使用Krajee Yii Extensions。所以我開始閱讀文檔。如何在yii2 alpha中預先添加/附加bootstrap3圖標到活動窗體

$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

+0

請不要使用「引導」標籤,使用「Twitter的自舉」,因爲這意味着別的 –

回答

7

這是一個問題,或者你向我們展示你是如何做到的?

你也應該能夠做到像:

<?= $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' => '']) ?> 
+0

我想要的「onClick」上「模板」內的按鈕。但它不起作用。請告訴我該怎麼做? –