Using Laravel Form class to add the 'disabled' attribute

眉间皱痕 提交于 2020-01-01 07:50:31

问题


Using Laravel 4's Form class, we can create a list using

 {{ @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?


回答1:


Just add array('disabled') in the end like:

{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}



回答2:


This should do the work.

 {{ @Form::select('colors', Colors::all()), array(
    'disabled' => 'disabled',
    'class'    => 'myclass'
    ) }}



回答3:


Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments are @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.



来源:https://stackoverflow.com/questions/17739699/using-laravel-form-class-to-add-the-disabled-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!