Hi,

I'm trying to create a one page complex (3 level) webform and I'm having problems with conditional logic.

The scenario:

- Option [ flight ] [ flight and hotel ]
- Rooms [1] [2]
- Room 1 {fieldset}
-- Adults [1][2][3]
-- Children [1][2][3]
- Room 2 {fieldset}
-- Adults [1][2][3]
-- Children [1][2][3]
- Room 3 {fieldset}
-- Adults [1][2][3]
-- Children [1][2][3]

The conditions:
1) if [Option] is "flight and hotel" then show [Rooms]
2) if [Rooms] is "1 room" OR if [Rooms] is "2 rooms" OR if [Rooms] is "3 rooms" then show { Room 1 }
3) if [Rooms] is "2 rooms" OR if [Rooms] is "3 rooms" then show { Room 2 }
4) if [Rooms] is "3 rooms" then show { Room 3 }

The problem:
If i select "flight and hotel", choose the rooms quantity and return to "flight", the {Room1}, {Room2} and/or {Room3} fieldsets stills there...

Example:
1) I click in the option [flight and hotel]
2) The [rooms] select list shows and then i select "3 rooms"
3) The fieldsets {Room1}, {Room2} and {Room3} will show...
4) If i click in the option "flight" the [rooms] select list will hide but the {Room 1}, {Room 2} and {Room 3} will remain visible...

Possible solutions:
a) if we implement "AND or OR logical groups" like in Rules, i could add a [option] validation AND a [rooms] group of OR, like this:

a.2) if [Option] is "flight and hotel" AND
{ if [Rooms] is "1 room" OR if [Rooms] is "2 rooms" OR if [Rooms] is "3 rooms" }
then show { Room 1 }
a.3) if [Option] is "flight and hotel" AND
{ if [Rooms] is "2 rooms" OR if [Rooms] is "3 rooms" }
then show { Room 2 }

b) or if we could "reset" the value of an option when he hides, i.e., if the [rooms] reset to "none" when hides (because i leave "flight and hotel" the rooms fieldsets will hide...

Thank you!

Comments

quicksketch’s picture

Ironically we just removed the "clear field values when hidden" behavior in #1677468: Non-text conditional component values deleted when hidden. I don't think we'd thought of this situation.

There is an identical request to this one at #1702274: Provide option to reset values on hiding fields, but this one has a much more thorough description so I'm going to mark that issue as duplicate.

quicksketch’s picture

Title: Conditional conflicts in a complex 3 level webform » Reset values when hiding conditional fields (Conditional conflicts in a complex 3 level Webform)
Category: support » feature

So I would think ideally we would handle this as follows:

- When hiding a field that was conditionally shown, store its current value and then reset it back to the defaults.
- The resetting of the defaults will hide any dependent fields on the now-hidden field.
- *If* the same field is shown again, restore its previous values.

Granted this is a huge pain, so I'm hesitant to undertake it. But it's a good request so I'll leave this open for reference.

liam morland’s picture

Or leave the field values as they are. When the form is submitted, figure out which fields are hidden at that time and set their values to null.

liam morland’s picture

liam morland’s picture

Version: 7.x-4.0-alpha4 » 7.x-4.x-dev

This issue would be much easier of we didn't have to do this part:

- *If* the same field is shown again, restore its previous values.

Would it be OK to do a simple implementation which doesn't do this extra saving and follow-up with another issue about saving these values? Doing it this way would also resolve #1840776: Components with a value that are hidden by conditionals should be empty.

liam morland’s picture

I would like to work on this bug. I just need direction if my proposal in #5 is acceptable.

quicksketch’s picture

Sure Liam, let's work on just getting it reset back to the default values for starters.

liam morland’s picture

Status: Active » Needs review
StatusFileSize
new840 bytes

Thanks. Here is a patch.

Maxime W’s picture

Here is the patch for javascript.
It recursively restores the hidden fields to their default value (as defined in the field configuration).

tame4tex’s picture

Patch #9 worked for me. Thanks!

liam morland’s picture

Issue summary: View changes
StatusFileSize
new840 bytes

Reroll.

quicksketch’s picture

Status: Needs review » Needs work

Thanks guys for the patches. Liam, in your #11, this code would have an issue with nested components (I think): $form_state['webform']['component_tree']['children'][$cid]. The "component_tree" array is nested into a tree structure.

I'm not sure about #9, that seems like it could have browser compatibility issues. Props for a clever use of the DOM to reset the form back to defaults. If others have success with that approach, please post your results.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB

Here is a version that recursively processes the component_tree.

liam morland’s picture

danchadwick’s picture

Status: Needs review » Needs work

@Liam Morland -- Can you educate me on where we are on hidden values as it relates to draft vs final and intrapage (javascript) and interpage (php)? In the related issue there is some discussion.

I think the most desirable behavior is to maintain the submitted data until the page is final, at which point it is removed if hidden. But the conditional code (both intra- and inter-page) consider hidden-but-present data as if it were blank.

Setting back to Needs work not because I've rejected the patch, but because I want to understand what the correct behavior is before I test the patch to see if it implements it.

danchadwick’s picture

Status: Needs work » Closed (duplicate)

All handled in the related issue.