Create a select component and use option groups in the options for it. Do not select Listbox. When viewing the form, PHP will issue a warning for each option group and the options inside a group will not display (it will say "Array" where the group should be).

This seems to happen because form_process_radios() does not handle nested options arrays. A proper fix would require this core function to be changed. In the meantime, Webform could insist on using a listbox whenever there are option groups. Thoughts on this solution?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Webform could insist on using a listbox whenever there are option groups.

Sounds good to me!

Liam Morland’s picture

Status: Active » Needs review
FileSize
1.66 KB

Patch attached.

quicksketch’s picture

I'm hesitant about this patch. While it makes sense to "set a default" instead of throwing a validation error for obvious oversights, I don't think that the "Listbox" option being automatically checked for users is necessarily an obvious configuration change that a user would expect. I was expecting a validation error instead, telling the user that option groups are only supported if the listbox option is enabled. A colleague of mine said it should perhaps change it automatically for you but display a warning message (while redirecting back to the component listing). I'm not sure whether that's more appropriate than a validation error or not, but I would like to avoid silently modifying the user's settings without giving them indication.

Liam Morland’s picture

I like the second suggestion better. A validation error forces the user to find the Listbox control and check it. If they are not familiar with the control they may be confused. Attached is a patch which includes setting a message to warn the user that a listbox will be used.

quicksketch’s picture

Status: Needs review » Fixed
FileSize
2.58 KB

Thanks Liam. I cleaned up the patch approach quite a bit but kept the general idea. Instead of modifying webform.component.inc, I wanted to keep the code in select.inc so I tacked on the necessary code to our element validate handlers. I tried to use a separate handler to keep them all separate, but I couldn't ensure that _webform_edit_validate_options() handler would run first (thus converting options for us). So instead I just implemented it directly in the existing validation handlers. This has the upside of preventing us from needing to convert the options again manually, since they're already an array by the time we want to check them.

I tested and committed this patch to both branches. Let me know if any further changes look necessary to you.

quicksketch’s picture

FileSize
599 bytes

Doh, found a bug when not using options element. Looks like we do still have to convert the list to options when using the plain text area. Patch applies on top the last one.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.