twaldron
twaldron

Reputation: 2752

Setting the HTML Id of an element with laravel

I have to following drop down list

 {{ Form::select('selected_site', $select_sites, Input::get('selected_site')) }}

it works fine and I see the name is "selected_site" but how do I set the HTMl Id of the element? I find nothing on this in documentation.

Thanks!

Upvotes: 2

Views: 1440

Answers (2)

Abishek
Abishek

Reputation: 11691

There are 2 ways to do this.

  1. You can setup a Label using the Laravel Form builder and use the same name on the control associated with it. As per the documentation at http://laravel.com/docs/html#labels (take a look at the note under this section) After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.

  2. As answered by @antonio-carlos-ribeiro, the 3rd parameter of the control takes a list of options on which you can setup the additional attributes for the control.

Hope this helps...

Upvotes: 3

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

There's one more argument:

{{ 
    Form::select(
                  'selected_site', 
                  $select_sites, 
                  Input::get('selected_site'), 
                  array('id' => 'yourid')
                ) 
}}

In this last one you can add anything else you need, 'class', 'data-whatever', etc.

Upvotes: 3

Related Questions