Problem/Motivation

A webform content author for one of our websites requested to have a new conditional for a date component. If an end-user picks a date that is specific day of the week (ex: Sunday), then show/hide another field.

Proposed resolution

I have used the other date conditionals as an example on creating a new conditional. It is currently working and I will upload the patch with this functionality for review.

Comments

nmillin created an issue. See original summary.

nmillin’s picture

Status: Active » Needs review
StatusFileSize
new4.02 KB
nmillin’s picture

StatusFileSize
new4.33 KB

Updated patch file. There was a bug where multiple days of the week could not be selected when using OR.

liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch. This will need tests.

The #options array does not need to specify the key since those are the keys they would have anyway by default.

Please ensure all functions have complete documentation including @param and @return.

nmillin’s picture

StatusFileSize
new4.21 KB

Thanks for the feedback. I'm going to update the patch based on what you said. Just updating the patch since it had duplicate code and I wanted to make sure others aren't using a bad patch file.

liam morland’s picture

Instead of having your own list of days, use webform_options_days().

nmillin’s picture

@Liam I might be missing something, but doesn't webform_options_days function need to have a webform $component passed into it?

Just looking into callback_webform_options and webform_options_days I wasn't sure if I can leverage webform_options_days for displaying the days of the weeks as a dropdown. If you could please point me in the right direction, that would be greatly appreciated. Thanks.

liam morland’s picture

It doesn't use any of its parameters. Just pass it NULLs.

nmillin’s picture

StatusFileSize
new6.49 KB

*facepalm* Thanks Liam.

Attaching an updated patch to use webform_options_days() & include complete documentation. I added to WebformTestCase.test for the match conditional values and mismatch conditional values, but I don't know how to debug the failing tests. Any chance you can point me in the right direction again?

liam morland’s picture

It looks like it is comparing a date array to the string day of the week. There are functions to convert dates to day of the week.

nmillin’s picture

StatusFileSize
new6.49 KB

I believe this will pass the tests now. There was a capitalization issue that was making a === return false. I want to make sure this passes the tests before I go further.

nmillin’s picture

Status: Needs work » Needs review

@Liam, I finally got back to this & it is passing now. Any chance you can review the patch and let me know what you think?

*Note* This does add 2 coding standards messages. They are:
1329 Type hint "Object" missing for $node
1797 Type hint "array" missing for $input_values

I'm assuming these aren't blockers at this time. Let me know if these need to be reviewed.

Thank you.

-Nate

mweixel’s picture

Was this ever resolved? We have exactly the same use case for a site that isn't ready for D9 yet. Has anyone tried applying the patch against a full release version of Webform or one of the later dev versions?

nmillin’s picture

@mweixel we've been using the patch in #11 (I wrote) for the last 2.5 years. It applies cleanly to the latest release (7.x-4.24). It would be great if you could test it out so this could be moved forward.

liam morland’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.