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

benjarlett created an issue. See original summary.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
The Webform module's issue queue is for bugs, feature requests, and planning. Please post general support questions to Drupal Answers. You can also ask questions or help answer questions on the #webform channel on Drupal Slack.

This is a support request but it has steps to reproduce, which is unusual.

benjarlett’s picture

Category: Support request » Bug report
benjarlett’s picture

Maybe 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.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Your OptGroups must group the child options

The below code will work as expected.

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'