我从Laravel开始,我正在使用Illuminate / Html制作表格。
我想在第一个选项中添加禁用属性,但我找不到这样做的方法。
{!! Form::open(['url' => 'shelter/pets']) !!}
<div class="form-group">
{!! Form::label('pet_type','Type:') !!}
{!! Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Add pet', null, ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
只需通过disabled
的options
。尝试 -
{!! Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control', 'disabled' => true]) !!}
您可以在php中手动循环遍历数组或使用jquery。
$('select.someclass option:first').attr('disabled', true);
从源头看,看起来不可能。 <select>
元素是在https://github.com/illuminate/html/blob/master/FormBuilder.php#L532建立的
传递的唯一args是值,名称和选定的布尔值。看起来你有2个解决方案。使用javascript(argh),或使用类似str_replace
的东西。
<?php
$field = Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control']);
// find value="Select Type" and replace with value="Select Type" dialled
echo str_replace('value="Select Type"', 'value="Select Type" disabled', $field);
?>
这可能不是您正在寻找的,但它会阻止用户选择第一个选项,但仍然在列表中。
Form::select
支持A Grouped List
,你可以这样使用它。
{!! Form::select('pet_type', ['Select Type' => ['dog', 'cat']], 0, ['class' => 'form-control']) !!}
最后一个数组用于形成html标记的属性,因此您可以简单地将其禁用到其中:
{!! Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control', 'disabled' => 'disabled']) !!}
这可以帮到你
Form::select('name_select', '', null, ['name' => '', 'id' => '', 'disabled' => 'disabled'])