Answer the question
In order to leave comments, you need to log in
Can I set my own parameters in the ActiveForm template?
$form = ActiveForm::begin([
'id' => 'login-form',
'fieldConfig' => [
'template' => '{icon}{input}{error}'
],
]);
Answer the question
In order to leave comments, you need to log in
To do this, apparently, you need to override yii\widgets\ActiveField
, or rather the 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();
}
// добавить это
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;
}
$form = ActiveForm::begin([
'fieldClass' => 'my\widgets\ActiveField'
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question