Skip to content

Conversation

@nashby
Copy link
Contributor

@nashby nashby commented Feb 18, 2012

No description provided.

josevalim pushed a commit that referenced this pull request Feb 20, 2012
add selected and disabled options to grouped select
@josevalim josevalim merged commit b62f5a9 into rails:master Feb 20, 2012
@nozpheratu
Copy link

Setting the selected option always makes the group select default to the first available option for me given the following code for simple_form:

= f.input :state_or_province, :collection => Country.order(:name), :as => :grouped_select, :group_method => :states, :selected => params[:passed][:school][:state_or_province]

@rafaelfranca
Copy link
Member

@12eebok As far I remember this fix is only in the master branch.

@nozpheratu
Copy link

@rafaelfranca You sure? Setting disabled seems to work just fine for me, I'm just having trouble with the selected option.

@rafaelfranca
Copy link
Member

I'm not sure, maybe this is a SimpleForm issue. have you tried the plain grouped_collection_select?

@nozpheratu
Copy link

The form_for equivalent:

f.grouped_collection_select :state_or_province, Country.order(:name), :states, :name, :id, :name, {:selected => params[:passed][:school][:state_or_province]}, {:disabled => true}

Produces exactly identical output with my default option being Zabul(first option in the collection) in both cases:

<select name="school[state_or_province]" id="school_state_or_province" class="grouped_select optional">
 ....
   <optgroup label="Afghanistan">
      <option value="15">Zabul</option>
       ...

Expected output given a key value of 448:

<optgroup label="Canada">
      <option selected="selected" value="448">Manitoba</option>
  ...

Unless I'm not passing the selected option correctly I don't think it's a simple_form issue.

@rafaelfranca
Copy link
Member

Yes, this fixes is only to master.

@rafaelfranca
Copy link
Member

Here the relevant code https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_view/helpers/form_options_helper.rb#L606 see the last argument of the option_groups_from_collection_for_select method

@nozpheratu
Copy link

Good to know, thank you for your time

@rafaelfranca
Copy link
Member

If you want you can make a pull request with the tests in this one and you implementation (since the master branch and the 3-2-stable are very different in these helpers).

I could make it, but I don't have time now

@nozpheratu
Copy link

I'd be willing to give it a shot, but I'm still a little green to Github and even Rails for that matter so I'll have to do a little reading first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants