Using Laravel Form class to add the 'disabled' attribute
Solution 1
Just add array('disabled')
in the end like:
{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}
Solution 2
This should do the work.
{{ @Form::select('colors', Colors::all()), array(
'disabled' => 'disabled',
'class' => 'myclass'
) }}
Solution 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.
Related videos on Youtube
Nyxynyx
Hello :) I have no formal education in programming :( And I need your help! :D These days its web development: Node.js Meteor.js Python PHP Laravel Javascript / jQuery d3.js MySQL PostgreSQL MongoDB PostGIS
Updated on July 21, 2020Comments
-
Nyxynyx almost 4 years
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? -
Maciej Swic about 10 yearsHow do i add it to individual items in the array? I want some headers in the list.
-
Radek Sołdek almost 10 yearsThis is a more flexible and useful answer than the accepted one.
-
Radek Sołdek almost 10 years@MaciejSwic, there is a more complete answer below now
-
Haroon almost 10 yearshow can i add disable to the option element in that select??
-
Eugene van der Merwe over 7 yearsI have the same question as @MaciejSwic, how do I disabled individual options? How do I add styles to individual options?