Add support for HTML attributes of optgroups to select helper #43019
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #11517 updated
grouped_options_for_selectto allow passing HTML attributes of the optgroup as the last element of each array, which is called internally byselectwhen it detects grouped choices.However, the
selecthelper 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 withgrouped_options_for_select, which assumes the individual options are the second element, not the last element.Now there's agreement between
selectandgrouped_options_for_selectin 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!