P
P
Pavel Gogolinsky2016-03-24 16:11:36
Yii
Pavel Gogolinsky, 2016-03-24 16:11:36

How to move checkbox from label to CheckboxList in Yii?

Generating a checkboxlist

Html::checkboxList('season', false, ['Зима', 'Лето', 'Демисезон']])

I get such a layout
1b32e28dcf474f42a6c4023bcba96e74.png
How to change the list template so that the input of the checkbox is before the label, and not in it?
I need to customize the checkbox, for this I want to separate the checkbox icon from the label

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Gogolinsky, 2016-04-04
@gogolinsky

Decided so

Html::checkboxList(
            'attribute',
            false,
            $options,
            [
                'item' => function($index, $label, $name, $checked, $value) {
                    $checkedLabel = $checked ? 'checked' : '';
                    $inputId = str_replace(['[', ']'], ['', ''], $name) . '_' . $index;

                    return "<div><input type='checkbox' name=$name value=$value id=$inputId $checkedLabel>"
                    . "<label for=$inputId>$label</label></div>";
                }
            ]
        );

H
holfza, 2016-03-24
@holfza

Html::checkboxList('season', false, ['Зима', 'Лето', 'Демисезон'],['template' => '{input}{label}'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question