Skip to content

Conversation

@cgunther
Copy link
Contributor

PR #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, 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, 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.

Since this mismatch existed since v4.1 (when #11517 was merged), if this can be backported to at least v6.1, that'd be much appreciated to avoid having to wait for v7.0 to be released to take advantage of.

Thanks!

@rails-bot rails-bot bot added the actionview label Aug 15, 2021
@rails-bot
Copy link

rails-bot bot commented Nov 13, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Nov 13, 2021
@cgunther cgunther force-pushed the av-select-optgroup-html-attrs branch from 87540cf to a2d15a1 Compare November 15, 2021 15:10
@rails-bot rails-bot bot removed the stale label Nov 15, 2021
@cgunther
Copy link
Contributor Author

Rebased to resolve staleness. This is still an issue.

@rails-bot
Copy link

rails-bot bot commented Feb 13, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Feb 13, 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.
@cgunther
Copy link
Contributor Author

Rebased to resolve staleness. This is still an issue.

@cgunther cgunther force-pushed the av-select-optgroup-html-attrs branch from a2d15a1 to 0387cc1 Compare February 14, 2022 14:51
@rails-bot rails-bot bot removed the stale label Feb 14, 2022
@deepakhb2
Copy link

Is this still an issue? I can review and test the change.

@rafaelfranca rafaelfranca merged commit db5a6ef into rails:main Nov 23, 2022
rafaelfranca added a commit that referenced this pull request Nov 23, 2022
@cgunther cgunther deleted the av-select-optgroup-html-attrs branch June 2, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants