使用 Laravel Form 类添加 'disabled' 属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17739699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Laravel Form class to add the 'disabled' attribute
提问by Nyxynyx
Using Laravel 4's Form class, we can create a list using
使用 Laravel 4 的 Form 类,我们可以创建一个列表
{{ @Form::select('colors', Colors::all()), $color }}
Question:How can we add the attribute disabled
using Blade without having to rewrite the clean Blade syntax into the usual ugly form?
问题:我们如何disabled
使用 Blade添加属性而不必将干净的 Blade 语法重写为通常的丑陋形式?
回答by JustinHo
Just add array('disabled')
in the end like:
只需array('disabled')
在最后添加:
{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}
回答by PJunior
This should do the work.
这应该可以完成工作。
{{ @Form::select('colors', Colors::all()), array(
'disabled' => 'disabled',
'class' => 'myclass'
) }}
回答by Edmund Sulzanok
Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments are
@Form::select('name', $optionsArray, $selectedOption, ['disabled'])
.
尽管已经回答,但 IMO 的两个答案都不够中立,因此为避免重复,参数为
@Form::select('name', $optionsArray, $selectedOption, ['disabled'])
.
So if you're prepopulating form with @Form::model()
you should do @Form::select('name', $optionsArray, null, ['disabled'])
- array with 'disabled' has to be 4th parameter.
因此,如果您要预先填充表单,@Form::model()
您应该这样做@Form::select('name', $optionsArray, null, ['disabled'])
- 带有“禁用”的数组必须是第 4 个参数。