If a select element has an empty options list an empty select is shown or, if the select is shown as checkboxes/radio buttons, only the form element's label is shown.
The element should not be shown at all.

Comments

Sneakyvv’s picture

Assigned: Sneakyvv » Unassigned
Status: Active » Needs review
StatusFileSize
new695 bytes

I've attached a patch, which makes the select inaccessible.

quicksketch’s picture

Issue summary: View changes
Status: Needs review » Needs work

I don't think the field should be hidden entirely. My expectation would be that the select list would be present but be empty. I suppose there's no such thing as an "empty" set of checkboxes or radios though. Still, I think the element should be present but have a message or indicator there are no valid options. If the field was entirely hidden, as an end-user I'd think there was a problem with the module, rather than the view simply being empty.

So I think we should handle this scenario, but rather than hiding the entire select component, some kind of placeholder should be present.

mostovoy’s picture

Hi.

I tried it on Webform 4, but does not work. I think it should work.

I really need it. Any help is welcome.

Thanks, regards

redeight’s picture

I've had this issue as well. My 'solution' was to pop in a default row of {null-key}|{Notification of no options available}.
Of course, this requires that you then handle the special option correctly. If the form needs to block submission when no option is available you may need to set up a conditional to throw an alert when the {null-key} option is selected.

mostovoy’s picture

Thanks ! RedEight:

I need to hide the element but I using tokens fields like %username (Webform 3)

Can you help me?

Thanks ! a lot.

danchadwick’s picture

Version: 7.x-3.19 » 7.x-4.x-dev
Status: Needs work » Needs review

This won't be addressed in 7.x-3.x, but should be in 7.x-4.x and 8.x.

I'm mixed about how how to handle this. The proposed patch is simple, and this is not a common case. Adding some sort of placeholder message creates the possibility of wanting to customize the placeholder message. I can imagine lots of use cases where having the placeholder isn't helpful, such as "No color options are available for this SKU". Why tell me that?

OTOH, quicksketch likes the placeholder approach.

I propose to accept the patch (re-rolled as needed).

Status: Needs review » Needs work

The last submitted patch, 1: webform-hide-empty-select-2117593-1.patch, failed testing.

valentine94’s picture

Status: Needs work » Needs review
StatusFileSize
new737 bytes

Re-roll.

valentine94’s picture

StatusFileSize
new738 bytes

Small coding standards fix.

Please review.

  • DanChadwick committed fe69e59 on
    Issue #2117593 by Valentine94, DanChadwick: Fixed Select with empty (pre...
  • DanChadwick committed 005fc62 on
    Issue #2117593 by Valentine94, DanChadwick: Fixed Select with empty (pre...
danchadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Status: Needs review » Fixed
StatusFileSize
new2.52 KB

Thanks @valentine94 for the re-roll. But please do test the patch before submitting it/them. There is no way for this patch to work because it sets the element's #access, which is then immediately overwritten in _webform_client_form_add_component().

The #10 patch prevents the overwrite. Note that it does NOT affect the display of a submission, since in this case the list of options is not built. Since this issue handles an edge case, I did not deem it worthwhile to generate the list of options just to hide the submission.

Committed to 7.x-4.x and 8.x

Status: Fixed » Closed (fixed)

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

nod_’s picture

This commit broke form builder, specifically, adding new option/checkboxes elements. the #access = FALSE in select.inc is the culprit.

danchadwick’s picture

Status: Closed (fixed) » Active

@nod_ - I don't use form_builder. Can this be fixed in form_builder? If so, you could post a patch to its issue queue and refer to this issue. Otherwise I'd welcome a webform patch that is form_builder friendly and still fixes this issue.

nod_’s picture

I'm not familiar with either module code so I don't know if it can be fixed from form_builder properly. Reverting this commit makes things work for my demo.

I'm rather short on time this week so I'll have to get back to it later.

markus_petrux’s picture

Status: Active » Closed (fixed)

Can this be fixed in form_builder?

Please, see the new patch attached to #2383285: Options element stopped working

danchadwick’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Sneakyvv’s picture

half this patch (everything in components/select.inc) is mine, but no credits... This sucks!

danchadwick’s picture

@Sneakyvv -- sorry. I picked up a year-old, forgotten issue, fixed it, committed it, and gave credit to the last working patch. I overlooked the work from the prior patch.