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
Building #options using YAML is not intuitive for most users and the current interface requires YAML for option groups.
Proposed resolution
Extend the completed UI for editing options to allow for option groups.
Comment | File | Size | Author |
---|---|---|---|
#2 | create-ui-for-editing-options-with-optgroups.patch | 12.54 KB | scott_euser |
Comments
Comment #2
scott_euser CreditAttribution: scott_euser commentedI have taken a first stab and this and it seems to work well for existing YAML with optgroups. There is currently no way to 'upgrade' the options to allow for optgroups. Was thinking a button or link like 'Enable option groups' perhaps?
Also there is a bug in the way the value callback is, so when you add options or optgroups more than once it doesn't remember what type the previously added rows are until saving.
Thought it anyway best to let you have a look at my progress on this and let me know if it's completely off the mark, etc.
Thanks!
Scott
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer commented@scott_euser You are moving in the right direction but this is going to be a very challenging task. Just setting up the options element was exhausting for me. I am procrastinating on building the #states UI
Some immediate thoughts...
Comment #4
scott_euser CreditAttribution: scott_euser commented@jrockowitz Thanks, yeah it's not a simple thing, agreed!
Thanks for all your points, all make sense and I'll keep progressing on it. Yeah I've been using the test-element-options but I deleted the non-optgroup ones for easier debugging which is why I missed the fatal errors, I'll be sure to add those back in to make sure it doesn't break those.
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedComment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedBased on the work I did for the #state conditional logic element, there is probably any opportunity to rework and significantly improve this element.
Comment #7
fenstratMoving to Webform queue, see #2827845: [roadmap] YAML Form 8.x-1.x to Webform 8.x-5.x.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer commentedI am closing this ticket for now. If someone wants to supply an update patch, please reopen this ticket.
Comment #9
code-brighton CreditAttribution: code-brighton commentedIf anyone gets here and is stumped at how to edit the yaml to add option groups manually. It's like this:
etc...
Would be cool to have it working in the interface though...if I get some time I'll have a look at your patch guys...thanks for the great work on this module!
Comment #10
jrockowitz CreditAttribution: jrockowitz as a volunteer commented@code-brighton The patch is now outdated.
OptGroup support is going to very difficult to add the UI. We would have to build a completely custom widget/element to manage it.
Comment #11
code-brighton CreditAttribution: code-brighton commented@jrockowitz thanks for getting back so quickly! When I made the change in the source I returned to edit the individual select field and was pleasantly surprised to see the edit area was now forced to be the source input. My main concern was an edit wiping my option groups. This isn't a problem so thanks :)
Comment #12
code-brighton CreditAttribution: code-brighton commented@jrockowitz All working well...However sadly this doesn't play with translations. All the rest of my form translates, but with the OptGroup select list for some reason the translation always reverts to English (or whatever the master language is) when I save.
Any ideas why this might be the case?
Comment #13
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commented@code-brighton Please create a new issue and document if OptGroups are not being translated via the global options (/admin/structure/webform/config/options/manage) or webform specific options.