Can I ask your settings in ActiveForm template?

$form = ActiveForm::begin([
 'id' => 'login-form',
 'fieldConfig' => [
 'template' => '{icon}{input}{error}'
],
 ]);


Is it possible to add the template variable "icon" in this way? And where is it defined then?

UPD: it Seems that only so https://stackoverflow.com/questions/23311242/yii2-...
June 5th 19 at 21:25
2 answers
June 5th 19 at 21:27
To do this, apparently you need to override yii\widgets\ActiveField, but rather methods in it:
public $template = "{label}\n{icon}\n{input}\n{hint}\n{error}";
 public function render($content = null)
{
 if ($content === null) {
 if (!isset($this->parts['{input}'])) {
$this->textInput();
}

 // add this
 if (!isset($this->parts['{icon}'])) {
$this->icon();
}

 if (!isset($this->parts['{label}'])) {
$this->label();
}
 if (!isset($this->parts['{error}'])) {
$this->error();
}
 if (!isset($this->parts['{hint}'])) {
$this->hint(null);
}
 $content = strtr($this->template, $this->parts);
 } elseif (!is_string($content)) {
 $content = call_user_func($content, $this);
}

 return $this->begin() . "\n" . $content . "\n" . $this->end();
 }

public function icon($content, $options = [])
{
 $this->parts['{icon}'] = Html::tag('i', null, ['class' => 'icon-'.$this->attribute];

 return $this;
 }

and use it in the form using:
$form = ActiveForm::begin([
 'fieldClass' => 'my\widgets\ActiveField'
]);
June 5th 19 at 21:29
1.
"$icon{input}{error}"

2. before input
<?= $form--->field($model, 'username') ?>
<?= $form--->field($model, 'password') ?>


Here's an example. Want was icon username = 'username' and password icon = 'password'
What you wrote won't work - ezekiel_Rohan commented on June 5th 19 at 21:32

Find more questions by tags Yii