V
V
Vladimir2021-02-17 22:02:04
Yii
Vladimir, 2021-02-17 22:02:04

How to remove the top Label and input when displaying $form->field()->checkboxList()?

When called

<?= $form->field($formFilter, 'category', [
    'options' => [
        'tag' => 'fieldset',
        'class' => 'search-task__categories'
    ]
])->checkboxList(Category::getCategorisList(), [
    'tag' => false,
    'item' => function ($index, $label, $name, $checked, $value) {
        return '<label class="checkbox__legend">' .
            Html::checkbox($name, $checked, [
                'class' => 'visually-hidden checkbox__input',
                'value' => $value
            ]) . '<span>' . $label . '</span>                    
                </label>';
    }
]); ?>

I get
602d6803bc9be033962794.jpeg
an extra label and iput appear, how to remove them and put the legend tag instead of them with the same content as the label

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
toratoda, 2021-02-18
@toratoda

to remove label : to remove input: to add legend it is better to inherit your ActiveField in which to replace the function->label(false)

public function label($label = null, $options = [])
so that it renders legend and specify this new class in the form.

V
Vladimir L, 2021-02-18
@Lobochkin

Thanks to everyone who responded, I managed to figure it out myself, that's what happened

<?= $form->field($formFilter, 'category', [
                "template" => Html::tag('legend',"{labelTitle}") . "\n{input}",
            'options' => [
                'tag' => 'fieldset',
                'class' => 'search-task__categories',
            ]
        ])->checkboxList(Category::getCategorisList(), [
            'unselect' => null,
            'tag' => false,
            'item' => function ($index, $label, $name, $checked, $value) {
                return Html::beginTag('label',['class' =>'checkbox__legend']) .
                    Html::checkbox($name, $checked, [
                        'class' => 'visually-hidden checkbox__input',
                        'value' => $value
                    ]) . Html::tag('span',$label) . Html::endTag('label');
            }
        ]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question