A
A
Alexander Stepanov2018-02-26 13:25:48
Yii
Alexander Stepanov, 2018-02-26 13:25:48

Why doesn't the state of the radiobutton change when clicking on the label?

I want to make beautiful buttons, but when you click on the label, nothing happens, although when you hover over the label, there is a glare on the radiobutton.
When you click on the circle itself, everything works, but for styling, you need to click on the label.
I took the layout from the bootstrap site and it works there when I click on the label, but I don’t understand what’s the catch. I
display the radio in a loop

<form class="form-inline" data-toggle="buttons" data-id="size" id="size">


                    <?php foreach ($product->sizes as $size): ?>

                        <div class="form-check">
                            <input class="form-check-input" name="size" type="radio" id="<?= $size->name ?>" value="<?= $size->name ?>" />
                            <label class="form-check-label" for="<?= $size->name ?>"><?= $size->name ?></label>
                        </div>

                    <?php endforeach; ?>

                </form>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Stepanov, 2018-02-26
@Exebeche

And dug himself, after writing the question.
Maybe someone else will come in handy
Add js and rejoice

$('.form-check').click(
    function(){
        $(this).find(':radio').attr('checked','checked');
        //выделение всех чекбоксов на кликнутом контейнере, снять выделение через removeAttr("checked")
});

B
BenDigget, 2021-12-24
@BenDigget

Friends, why is it so difficult?
Give the input an id and use the for attribute on the label

<label for="ch2">  Женский</label> <input type="radio" id="ch2">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question