Simple question, I hope.
I need to add a default value to my select list 'Please Select', and set it to disabled.
<select name="myselect" id="myselect">
<option value="" disabled>Please Select</option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
</select>
My current laravel form::select is
{{
Form::select(
'myselect',
$categories,
$myselectedcategories,
array(
'class' => 'form-control',
'id' => 'myselect'
)
}}
How can I amend this to include the default option value?
You can use array_merge
like this:
{{
Form::select(
'myselect',
array_merge(['' => 'Please Select'], $categories),
$myselectedcategories,
array(
'class' => 'form-control',
'id' => 'myselect'
))
}}
Alternatively you can set the placeholder somewhere before the select:
$categories[''] = 'Please Select';
To add the disabled attribute you can try this: (untested)
{{
Form::select(
'myselect',
array_merge(['' => ['label' => 'Please Select', 'disabled' => true], $categories),
$myselectedcategories,
array(
'class' => 'form-control',
'id' => 'myselect'
))
}}