How to disable a item of select box

Hi

I want to disable only one item of select box.

I tried to used :disabled=>'item' but it disable select box itself.

So anybody how to do this?

Thanks
Brijesh Shah

Brijesh Shah wrote:

Hi

I want to disable only one item of select box.

I tried to used :disabled=>'item' but it disable select box itself.

So anybody how to do this?

Thanks
Brijesh Shah

Hi Brijesh,

I hope the following example would help you.. If not put your code
here..

Example:

  select("post", "category", Post::CATEGORIES, {:disabled =>
'restricted'})

could become:

  <select name="post[category]">
    <option></option>
    <option>joke</option>
    <option>poem</option>
    <option disabled="disabled">restricted</option>
  </select>

I hope the following example would help you.. If not put your code
here..

Example:

  select("post", "category", Post::CATEGORIES, {:disabled =>
'restricted'})

could become:

  <select name="post[category]">
    <option></option>
    <option>joke</option>
    <option>poem</option>
    <option disabled="disabled">restricted</option>
  </select>

Thanks for your reply..

But this code does not work..there is no effect on select box.

if I tried this, select("post", "category", Post::CATEGORIES,{},
{:disabled =>
'restricted'}) then select box is disabled rather than one item..

read rails doc,there is one noticed thing.

{:disabled =>‘restricted’} is valid hint
'restrcted’must be select value,can imply disabled function.

eg:
<%= select(“message”, “id”, Message.all.collect {|p| [ p.title, p.id ] }, { :disabled => 16 })
%>

and view render code:

test select disabled values

	<select id="message_id" name="message[id]"><option value="14">第一</option>

<option value="15">第二</option>
<option value="16" disabled="disabled">第三</option></select>

tommy xiao wrote:

read rails doc,there is one noticed thing.

{:disabled =>'restricted'} is valid hint
'restrcted'must be select value,can imply disabled function.

eg:
    <%= select("message", "id", Message.all.collect {|p| [ p.title, p.id
]
}, { :disabled => 16 })
     %>

and view render code:

  test select disabled values

  <select id="message_id" name="message[id]"><option
value="14">第一</option>
<option value="15">第二</option>
<option value="16" disabled="disabled">第三</option></select>

Thanks for help...

Actually I tried with :disabled =>"16" instead of 16
and thats why I did not get result...

Now it works fine...