Answer the question
In order to leave comments, you need to log in
radioList yii2 override?
there is a form
<?=$form->field($model,'created_at')->radioList(['Radio 1', 'Radio 2', 'Radio 3'],['class'=>'mt-radio-list', 'itemOptions'=>['labelOptions'=>['class'=>'mt-radio mt-radio-list-outline']], 'item'=>function($label, $name){return "<label class='mt-radio mt-radio-outline'>$name<input type='radio' value='1' name='optionsRadios'> <span></span></label>";}]); ?>
public function radioList($items, $options = [])
{
$this->adjustLabelFor($options);
$this->errorOptions = array_merge(['tag' => 'span'], $this->errorOptions);
$this->parts['{input}'] = Html::activeRadioList($this->model, $this->attribute, $items, $options);
return $this;
}
Answer the question
In order to leave comments, you need to log in
I have my ActiveField in which I work, but the question remains open, how can I define 'item'=>function() in the method, so that when passing parameters like myRadioLis(['1','Radio']) my template is displayed ?
That is, I need to have such an output for each parameter
Here I found a solution, who will be interested
instead
of doing
return Html::beginTag('label') .
Html::Tag('input','',$options).
Html::beginTag('span') .
Html::endTag('span') .
Html::endTag('label');
There are cases when it's easier to just write html than to use ActiveField
But I don't understand why the bulkiness confuses you? Read the docs, etc. There is no limit on the length of a line of code anywhere.
But you can write your own ActiveField and create the myRadioList method there and put everything there. There will only be:
And you can make a widget, it will be:
<?=$form->field($model,'created_at')->myRadioWidget()?>
If I understood the question correctly, in the simplest implementation something like this:
public function radioList($items, $options = [])
{
if (key_exists('item', $options) === false) {
$options['item'] = function($label, $name){
return "<label class='mt-radio mt-radio-outline'>$name<input type='radio' value='1' name='optionsRadios'> <span></span></label>"
}
}
return parent::__radioList($items, $options);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question