以Laravel形式添加默认值以选择列表:: select [英] Add default value to select list in Laravel form::select

查看:72
本文介绍了以Laravel形式添加默认值以选择列表:: select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是一个简单的问题.

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>

我当前的laravel形式:: 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?

推荐答案

您可以像这样使用 array_merge :

{{
Form::select(
    'myselect',
    array_merge(['' => 'Please Select'], $categories),
    $myselectedcategories,
    array(
        'class' => 'form-control',
        'id' => 'myselect'
    ))
}}

或者,您可以在select之前的某个位置设置占位符:

Alternatively you can set the placeholder somewhere before the select:

$categories[''] = 'Please Select';

更新

要添加禁用的属性,您可以尝试以下操作:(未测试)

Update

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'
    ))
}}

这篇关于以Laravel形式添加默认值以选择列表:: select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆