Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I want to make a form with a select, with option groups
Steps to reproduce
heres my yaml code (found out how to do this from other issues in this queue)
test:
'#type': select
'#title': Test
'#options':
'Opt Group 1':
'something else': 'something else'
'another thing': 'another thing'
'Opt Group 2':
'yet something else': 'yet something else'
'yet another thing': 'yet another thing'
'#empty_option': 'please select'
however when I save it it becomes (I guess the parser is doing this).
test:
'#type': select
'#title': Test
'#options':
'Opt Group 1': null
'something else': 'something else'
'another thing': 'another thing'
'Opt Group 2': null
'yet something else': 'yet something else'
'yet another thing': 'yet another thing'
'#empty_option': 'please select'
And then the Opt Group 1 (&2) become standard options.. am I missing something?
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedThis is a support request but it has steps to reproduce, which is unusual.
Comment #3
benjarlett CreditAttribution: benjarlett commentedComment #4
benjarlett CreditAttribution: benjarlett commentedMaybe it needed to be a bug report then? I felt like it was in a grey area incase I was wrong that it was a bug, but in looking at it again it does feel like one. I guess the grey area comes about because in order to create optgroups I had to use the issue queue to find out how because I understand that in order to include optgroups in the UI it would be a lot of work with limited use (I guess most people dont like optgroups - though it does make sense when you want to create a single choice selector with two or more distinct groups of selections.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedYour OptGroups must group the child options
The below code will work as expected.