While digging around the same-page conditional code I came to wonder what was the meaning of the (undocumented) existingValue argument for the JS-comparison handlers.

It seems they are needed for rule groups that span multiple form pages. Example:

  • page1 (1 component): one
  • page2 (2 components): two, one & two (depending on both one and two).

With the current code on page2 the full conditional group is put into the settings. Because the form element for one is not present on page2 its value is passed in the settings and then passed to the comparson callback as existingValue.

I think this could be simplified easily by evaluating the comparison callbacks for components from earlier pages on the server side. This would remove a pitfall from implementing new comparison operators and conditional types.

Comments

torotil created an issue. See original summary.

torotil’s picture

Status: Active » Needs review
StatusFileSize
new12.98 KB

Here is a simple implementation of this idea. These are the changes made:

  • Factor out the server-side comparison evaluation into WebformConditionals::executeComparison().
  • Introduce a new source_type for JS evaluation that simply provides the evaluated value.
  • If a component from a previous page is rendered for a component rule in webform_conditional_prepare_javascript() render a “result” rule instead.
  • Change the existing comparisons to just ignore the now unused existingValue argument. Comparison operators are guaranteed to only be invoked on the same page as their element.

In an ideal world we could even make further calculations on the server-side to eliminate the already evaluated rules (and possibly some others as well).

torotil’s picture

Note that I didn’t remove the existingValue parameter to keep API-compatibility.

torotil’s picture

Issue summary: View changes
torotil’s picture

Issue summary: View changes
liam morland’s picture

At this point in the D7 life cycle, I wonder about the value of a big change like this.

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.