Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails - disable select tag

I am trying to disable a select tag. The options to fill our not database attributes but rather an array of integers, so collection_select doesn't seem to work in this situation.

technique 1:

select_tag(:zev_qty, options_for_select(display_quantity(@order_subject_supplies_request.site), {:disabled => display_quantity(@order_subject_supplies_request.site)}))

def display_quantity(site)
  if site
    site.open_site? ? [[0,0],[1,1],[2,2]] : [[0,0],[1,1]]
  else
    []
  end
end

The above is not what I want. It disables the options not the select tag.

technique 2:

f.select(:zev_qty, display_quantity(@order_subject_supplies_request.site), {:disabled => true})
  def display_quantity(site)
    if site
      site.open_site? ? [0,1,2] : [0,1]
    else
      []
    end
  end

The above doesn't work. None of the options are disabled.

While the correct values display in dropdown in both cases, the select tag is not disabled, and note that in this example, I just set disabled to true, but of course I would be conditionally disabling the select tags.

like image 953
JohnMerlino Avatar asked Jun 25 '12 15:06

JohnMerlino


1 Answers

The select method is defined as

f.select(method, choices, options = {}, html_options = {}),

so your second attempt was almost correct, except that the disabled option must be specified in a hash that is the fourth parameter in order to apply as an attribute to the select tag itself.

like image 126
cdesrosiers Avatar answered Sep 28 '22 22:09

cdesrosiers