Josh Johnson
Josh Johnson

Reputation: 563

:disabled field not working in fields_for

I'm trying to add a disabled drop-down box to my table, which I will eventually make conditional. However, disabled doesn't seem to be added to the line when it is run.

If I inspect the element in the page, manually adding disabled works, but it is not being added at run-time.

= f.fields_for(:targets, qualification.target_for(@grandfather.user)) do |builder|
  %tr
    %td
      = builder.select :completed, qualification.level_options.map{|o| [o,o]}, :disabled => "disabled"
      = builder.hidden_field :qualification_id, :value => qualification.id
      = builder.hidden_field :id

Upvotes: 4

Views: 1865

Answers (1)

Adam D
Adam D

Reputation: 414

Check out the API for Rails' Form Helper API

select(object, method, choices, options = {}, html_options = {})

It was adding :disabled => "disabled" to the options, instead of the html_options. This is the code to use instead (notice the empty hash for the options parameter):

builder.select(:completed, qualification.level_options.map{|o| [o,o]}, {}, {:disabled => "disabled"})

Upvotes: 4

Related Questions