Using Laravel Form class to add the 'disabled' attribute

47,777

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.

Share:
47,777

Related videos on Youtube

Nyxynyx
Author by

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, 2020

Comments

  • Nyxynyx
    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
    Maciej Swic about 10 years
    How do i add it to individual items in the array? I want some headers in the list.
  • Radek Sołdek
    Radek Sołdek almost 10 years
    This is a more flexible and useful answer than the accepted one.
  • Radek Sołdek
    Radek Sołdek almost 10 years
    @MaciejSwic, there is a more complete answer below now
  • Haroon
    Haroon almost 10 years
    how can i add disable to the option element in that select??
  • Eugene van der Merwe
    Eugene van der Merwe over 7 years
    I have the same question as @MaciejSwic, how do I disabled individual options? How do I add styles to individual options?