Php 如何使用Illumb/Html在Laravel中设置禁用的选择选项
我从Laravel开始,使用Illumb/Html制作表单 我想在第一个选项中添加disabled属性,但我找不到方法Php 如何使用Illumb/Html在Laravel中设置禁用的选择选项,php,forms,laravel,blade,illuminate-container,Php,Forms,Laravel,Blade,Illuminate Container,我从Laravel开始,使用Illumb/Html制作表单 我想在第一个选项中添加disabled属性,但我找不到方法 {!! Form::open(['url' => 'shelter/pets']) !!} <div class="form-group"> {!! Form::label('pet_type','Type:') !!} {!! Form::select('pet_type', ['Select Type','dog',
{!! 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() !!}
{!!表单::打开(['url'=>'收容所/宠物]])
{!!Form::label('pet_type','type:')
{!!Form::select('pet_type',['select type','dog','cat',0,['class'=>'Form control'])
{!!表单::提交('Add pet',null,['class'=>'btn btn primary Form control'])
{!!Form::close()!!}
只需通过选项中的禁用
。试试-
{!! Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control', 'disabled' => true]) !!}
您可以在php中手动循环数组,也可以使用jquery
$('select.someclass option:first').attr('disabled', true);
最后一个数组用于形成html标记的属性,因此您可以简单地将其传递到:
{!! Form::select('pet_type', ['Select Type','dog', 'cat'], 0, ['class' => 'form-control', 'disabled' => 'disabled']) !!}
从源头上看,这似乎是不可能的。
元素是在
传递的唯一参数是值、名称和选定的布尔值。看起来您有两种解决方案。使用javascript(argh),或者使用类似于str\u 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
支持分组列表
,您可以这样使用它
{!! Form::select('pet_type', ['Select Type' => ['dog', 'cat']], 0, ['class' => 'form-control']) !!}
更多详细信息:这可以帮助您
Form::select('name_select', '', null, ['name' => '', 'id' => '', 'disabled' => 'disabled'])
作为此处函数的签名:
vendor/laravelcollective/html/src/FormBuilder.php行#625:
所以你可以这样使用它:
{!! Form::select('pet_type',
['Select Type','dog', 'cat'],
0, //default selection
['class' => 'form-control'], //the select tag attributes
[ 0 => [ "disabled" => true ] ] //list of option attrbitues (option value is the arrays key)
) !!}
这是我第一次做的,但它禁用了所有的选择输入,我只想禁用第一个选项。就像我对V说的:这是我第一次做的,但它禁用了所有的选择输入,我只想禁用第一个选项。嗨,javipedrera,你得到答案了吗?如果你找到答案,请帮助我。我面临同样的问题:)
{!! Form::select('pet_type',
['Select Type','dog', 'cat'],
0, //default selection
['class' => 'form-control'], //the select tag attributes
[ 0 => [ "disabled" => true ] ] //list of option attrbitues (option value is the arrays key)
) !!}