Hi - not sure if this is some weird edge case, but we are having issues that when a pagebreak is introduced on a v complex form, it causes fields that were otherwise hidden due to unsatisfied conditions now showing.

I have attempted to strip down the form to just the bare minimum to demo this issue and have attached a node export file for it. This is using rc5 but also failed on earlier rcs.

Field 1 - checkbox - options = A, B
Field 2 - checkbox - option=A
Field 3 - textfieid for A
Field 4 - checkbox - option=B
Field 5 - textfieid for B

Conditions are aiming to cause only F3 and F5 to show if F1 has A selected, and ditto for B

As i say, this works just fine without a pagebreak, but as soon as we put one in above F2 then we end up seeing F5.

I am not trying to debate the logic of the field choices or condition structure since this really is a super simplified rendition of a very complex process - and the core point for me is this all works as a single form, and doesn't when we add the pagebreak.

The attached file already has the pagebreak in it - try it - then delete it - then confirm that the desired conditions do what is expected.

Anyone able to provide a steer on how we dig in to resolving this.

Comments

danchadwick’s picture

Just an update. I investigated and reproduced this bug. It is being caused by over-simplified logic in when to include a component on a page. When a component is hidden, but might be shown because it depends upon another component on the page, it is rendered and relies of javascript to hide it in the browser.

The checkbox is NOT included because it is hidden by a component on a previous page. The textfield IS included because it depends upon a component on this page, but that component was not rendered. Hence the javascript doesn't hide it.

petednz’s picture

hi Dan - thanks for verifying it wasn't just some misconfiguration on my part. And explaining it more lucidly. Any idea how i (or others) can begin to work on resolving this rather than finding awkward work arounds?

danchadwick’s picture

Status: Active » Needs review
StatusFileSize
new3.79 KB

Old behavior:

1) When determining whether a page is empty (and hence should be skipped by the next/prev page buttons), a field which depends upon at least one other field on the same page is considered shown. This causes pages to be displayed (such as in your example), when they shouldn't.

2) When determining whether to render a component on a page, if the component depends upon another component on the same page, it is always rendered, relying on the javascript to hide it. If, however, the source component was not rendered (because it depends solely upon components on other pages), then the javascript will be unable to hide it because the source component is missing from the page and cannot be triggered.

New behavior:

1) When determining whether a page is empty (and hence should be skipped by next/prev page), components which are currently hidden but depend upon other components are the same page are not considered shown. In your example, page two should not be shown at all if neither checkbox in field 1 is checked.

2) When determining whether a component should be rendered on a page, if the component would be hidden but depends upon at least one rendered component on the same page, it will be rendered. The javascript will then hide it.

The main bug in this issue is caused by the textfields depending upon the checkboxes (fields 2 and 4) which are absent from the form. Because they are absent, the javascript cannot trigger them to hide the text fields. With this patch, those text fields will not even be included on the form, unless their corresponding checkboxes are too.

This checking creates the possibility that determining the visibility of a component could cause an infinite loop due to cyclic dependencies in the conditions. This patch contains protection against this and will show the components should this (very unusual) situation occur.

3) If the visibility of a component has already been determined, it is cached and not determined again.

@petednz and others using conditions extensively - Please test this patch and let me know if it works for your complicated conditionals.

petednz’s picture

Thank you Dan - I expect to be able to test this today and will let you know how it goes

Status: Needs review » Needs work

The last submitted patch, 3: webform-intrapage_dependencies-2315541-3.patch, failed testing.

danchadwick’s picture

Status: Needs work » Needs review

Bugger off, testbot.

petednz’s picture

Status: Needs review » Reviewed & tested by the community

Hi Dan - tested, and with the example I provided it definitely fixed things. On the next 'more complex' step up it also worked - nice work.

For you interest (or not) the project that is benefitting from your support is the Australian Breastfeeding Association, in particular their training arm. cheers

I will next test it on the 'very' complex version of the webform.

just to note (for others) the patch fails against latest release but works against dev - Hunk #6 FAILED at 3074.

danchadwick’s picture

@petednz -- let me know about your "very" complex form. And, yes, the patch is against the current -4.x-dev.

petednz’s picture

Dan, has been tested on the mega form and performs as wished for - so again thanks. I have recommended they find other webforms with conditionals, if they have them, esp if they have pagebreaks, and confirm that they can find no undesired side affects.

  • DanChadwick committed 92f8bb4 on 7.x-4.x
    Issues #2315541 by DanChadwick: Fixed conditionality is broken by...
  • DanChadwick committed 586df99 on 8.x-4.x
    Issues #2315541 by DanChadwick: Fixed conditionality is broken by...
danchadwick’s picture

Status: Reviewed & tested by the community » Fixed

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

seschneck’s picture

StatusFileSize
new19.1 KB

Thanks to all for excellent support of this module.

I have a webform case using the matrix component where this still seems to occur despite Dan's patch. An export containing 2 variations on the problem is attached.

Clean install with:
Drupal 7.31
Views 7.x-3.8
Universally Unique ID 7.x-1.0-alpha5
Node clone 7.x-1.0-rc2
Node export 7.x-3.0
Webform 7.x-4.0-rc5+6-dev
Webform Matrix Component 7.x-4.x-dev
Webform Table Element 7.x-2.x-dev
Webform Validation 7.x-1.5

In the first case, the matrix component is on page 3, conditionally shown by a select on page 3. However, it still shows on page 1 and 2, and only is hidden properly on reaching the page where the select is rendered.

In the second case, the matrix component is shown conditionally by an "or" conditional that uses one select on page 1, and one select on page 3. In this case the matrix is hidden correctly on page 1, shows up on page 2, and hidden correctly again on page 3.

Perhaps this is unique to the matrix component in which case I am fine to move this comment to that issue queue. Thank you again!

petednz’s picture

seschneck’s picture

Correct, sorry for not clarifying.

Status: Fixed » Closed (fixed)

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