laravellaravel-bladelaravel-7laravelcollective

How to set form labels for radio buttons in Laravel 7


I have some radio buttons, and I would like the functionality that when the label is pressed, the radio button gets selected too - I think this is normal behaviour for a form.

{{ Form::radio('theme', 'default', true) }}
{{ Form::label('theme1', 'Group 1 (default)')}}

{{ Form::radio('theme', 'theme-2', false) }}
{{ Form::label('theme2', 'Group 2:')}}

{{ Form::radio('theme', 'theme-3', false) }}
{{ Form::label('theme3', 'Group 3:')}}

However, nothing currently happens when I click on the label. It works fine when I click on the circular radio button.

Is there something I am missing with the Laravel form? I can't find the documentation which shows which parameters I am meant to be passing in. Thanks.


Solution

  • Add ID to your radios:

    {{ Form::radio('theme', 'default', true, ['id' => 'theme1']) }}
    {{ Form::label('theme1', 'Group 1 (default)'])}}