2016-03-02 64 views
0

我在Yii2开发中使用kartik活动窗体,所以我想将图标添加到窗体域中。我跟着这个LINK及以下编码kartik activeform中的字体真棒使用 - yii2

//注册字体真棒

rmrevin\yii\fontawesome\AssetBundle::register($this); 

<?php $form = ActiveForm::begin(); 

    <?= $form->field($model, 'Bags_count',[ 
     'feedbackIcon' => [ 
     'default' => 'sort-numeric-desc', 
     'success' => 'ok', 
     'error' => 'exclamation-sign', 
     ] 
    ])->textInput()->hint('&nbsp;&nbsp; Example: 4'); ?> 

<?php ActiveForm::end(); ?> 

我发现通过使用Chrome检查元素的特性,这不需要编码尝试。希望这将有助于答案。

inspect element

form field

+1

默认图标karik-V的形式是glyphicon。 [见这里](https://github.com/kartik-v/yii2-widget-activeform/blob/master/ActiveFormAsset.php),你可以尝试通过改变[widget中的这一行](https:// github .com/kartik-v/yii2-widget-activeform/blob/master/ActiveField.php#L1053) –

+0

谢谢!现在工作 –

回答

1

您可以更改插件功能使用font-awesome-class

Kartik-v Active Form Widget

protected function renderFeedbackIcon() 
{ 
    if (!$this->_hasFeedback) { 
     return ''; 
    } 
    $config = $this->feedbackIcon; 
    $type = ArrayHelper::getValue($config, 'type', 'icon'); 
    $prefix = ArrayHelper::getValue($config, 'prefix', 'fa fa-'); 
    $id = Html::getInputId($this->model, $this->attribute); 
    return $this->getFeedbackIcon($config, 'default', $type, $prefix, $id) . 
    $this->getFeedbackIcon($config, 'success', $type, $prefix, $id) . 
    $this->getFeedbackIcon($config, 'error', $type, $prefix, $id); 
}