Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for html attributes to grouped_options_for_select #11517

Merged
merged 1 commit into from Jul 22, 2013

Conversation

nashby
Copy link
Contributor

@nashby nashby commented Jul 20, 2013

No description provided.

if divider
label = divider
else
label, container = container
end
body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label)

body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), { :label => label }.merge(html_attributes))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about splitting this line to make it more usable for reviewing on GitHub?

@pftg
Copy link
Contributor

pftg commented Jul 20, 2013

👍

@nashby
Copy link
Contributor Author

nashby commented Jul 20, 2013

@pftg hey, thanks for the comments! I didn't update tests since it already has a lot of long strings and actually I'm not sure what's the best way of splitting it :)

drogus added a commit that referenced this pull request Jul 22, 2013
add support for html attributes to grouped_options_for_select
@drogus drogus merged commit c43db55 into rails:master Jul 22, 2013
cgunther added a commit to cgunther/rails that referenced this pull request Feb 14, 2022
PR rails#11517 updated `grouped_options_for_select` to allow passing HTML
attributes of the optgroup as the last element of each array, which is
called internally by `select` when it detects grouped choices.

However, the `select` helper detected grouped choices by seeing if the
[last element is an Array](https://github.com/rails/rails/blob/6ec669b65d5cd47c984661920d670faccbf0920a/actionview/lib/action_view/helpers/tags/select.rb#L37),
meaning if you passed a hash of HTML attributes, it would no longer
treat the choices as grouped. This conflicted with
`grouped_options_for_select`, which assumes the individual options are
the [second element](https://github.com/rails/rails/blob/6ec669b65d5cd47c984661920d670faccbf0920a/actionview/lib/action_view/helpers/form_options_helper.rb#L546),
not the last element.

Now there's agreement between `select` and `grouped_options_for_select`
in expecting the individual option choices to be the second element,
allowing the hash of HTML attributes to exist as the last element and
properly trigger grouped options.
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.

None yet

3 participants