Radio button in Label tag in Laravel blade
Asked Answered
R

1

8

How to make this code into blade of laravel

<label class="radio" for="penyakit-0">
    <input name="penyakit" id="penyakit-0" value="Asma" type="radio">
    Asma
</label>

i've tried many ways to the radio button can be clicked from its text by using blade syntax, but still don't get anything right..

This is my blade syntax for that HTML:

<label class="radio" for="penyakit-0">
    {{ Form::radio('penyakit', 'Asma', array('id'=>'penyakit-0')) }} 
</label>
Rosenkranz answered 2/7, 2014 at 2:58 Comment(4)
Whats the problem exactly? Clicking the Asma text doesn't select the radio button?Persse
I mean. When i change syntax into blade like this: {{ Form::radio('penyakit', 'Asma', array('id'=>'penyakit-0')) }} it won't checked when I click the text 'Asma'Rosenkranz
It's perfectly fine to wrap the input in a label. So the accepted answer doesn't answer this specific question, unfortunately.Pappus
@phil-gyford Thanks bringing that to our attention! Edit made to the answer.Paulinepauling
P
15

Try:

{{ Form::label('penyakit-0', 'Asma') }}
{{ Form::radio('penyakit', 'Asma', false, array('id'=>'penyakit-0')) }}

Edit:

As Phil Gyford pointed out above, this Laravel snippet doesn't yield a label element with an embedded input element.

Unfortunately (or fortunately) by design design Laravel opted for the alternate construction using for attribute for some reason.

Paulinepauling answered 2/7, 2014 at 4:56 Comment(1)
You may use true instead if you want it checked.Paulinepauling

© 2022 - 2024 — McMap. All rights reserved.