So, the ability to select is/is not empty for dropdown conditionals seems quite handy. I'm currently adding it in a custom module, but thought I would contribute the change.

This almost works out of the box just by modifying _webform_conditional_operator_info, no more code required. However, in webform.js Drupal.webform.conditionalOperatorStringNotEmpty was not registering the select components as empty, so I changed it to be an exact inverse of the sister conditionalOperatorStringEmpty function.

This is not extensively tested, but it has worked nicely on my development server so far.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Hi @threewestwinds, thanks for the patch! This looks like a great patch. I think this wasn't included originally because you can accomplish this already by specifying individual options. However, I see the usefulness of just having a global empty/not empty without needing to specify anything, especially with something like checkboxes.

threewestwinds’s picture

Our forms were rather difficult to set up before I patched to our site, since the options list changed regularly (I'm using hook_webform_select_options_info to pull in terms from a taxonomy vocabulary). There was a lot of manual and error prone work.

Even if the "is / is not empty" part for select lists lives in a different module, I don't see a downside to reducing duplication with the .js change.

quicksketch’s picture

Yeah I like the new JS shortcut. No idea why I didn't just do that in the first place. I'll need to double-check if it causes any weirdness.

I think the empty/not empty feature is fine to include. It's probably better to have this option for the convenience over the small amount of confusion this might create when the option exists for something that doesn't quite make sense (like a set of radio buttons that would always have a value).

quicksketch’s picture

Issue summary: View changes

I finally reviewed this patch and it almost works, but using "is not empty" on a set of checkboxes doesn't work as expected. Apparently, checkboxes are always considered to be "not empty". I'll see if I can work this out.

quicksketch’s picture

Status: Needs review » Fixed
FileSize
2.2 KB

Here we go, all that was needed was to check that there was actually a value to loop over at all. If the returned value is an empty array, that now counts as empty. Previously the array had to contain an empty string to match.

Thanks for this patch @threewestwinds! Sorry it took forever to review and commit it.

Status: Fixed » Closed (fixed)

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

quicksketch’s picture

Marked #1638068: Add Additional Conditionals for Select Options duplicate, which has similar recommendations.

fenstrat’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Assigned: Unassigned » fenstrat
Status: Closed (fixed) » Patch (to be ported)

Needs porting to 8.x-4.x.

fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Assigned: fenstrat » Unassigned
Status: Patch (to be ported) » Fixed

Committed and pushed 5fd72fe to 8.x-4.x. Thanks!

  • Commit 805f4f7 on 8.x-4.x by fenstrat:
    Issue #2076409 by threewestwinds, quicksketch: Empty / Not Empty...

Status: Fixed » Closed (fixed)

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