Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better support for handling pages with no fields after randomization. #334

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

spivurno
Copy link
Contributor

@spivurno spivurno commented May 28, 2022

HS#34770

Customer was originally seeking a way to show the "Submit" button when the last page with fields had been reached. Previously, this snippet handled empty pages by automatically adjusting the target page to skip them on submission. It was feasible to dynamically change the name of the "Next" button when we knew that subsequent pages had no fields; however, this would not solve the issue where the pagination still showed additional pages.

I considered using JavaScript to interact with the pagination conditional logic to update the page navigation and button; however, I was honestly kind of curious about simply restructuring the form pages during the randomization rather than having to interact with the pagination conditional logic at all.

The basic logic is...

  1. Filter the fields based on the specified options.
  2. Get all the page numbers for the remaining fields (e.g. 1, 3, 4, 6).
  3. Loop through the page numbers and reassign them to their new page numbers based on the index of the page numbers array.
  4. As part of that loop, we also Inject the page field into the filtered fields and modify their page numbers accordingly.

I'm fairly happy with the result but I do have some concerns about brittleness. This has been tested with the customer's form extensively and it works with pages with only random fields, only static fields, and both random and static fields on the same page. Excited to see how this works in the wild!

Edit: Sept 30th, 2023

This ticket is requesting the same functionality (hiding pages with no fields) but in the context of Entry Blocks. Whatever lessons we find here can likely be applied there.

https://secure.helpscout.net/conversation/2373971553/55284/

@spivurno
Copy link
Contributor Author

Given the level of effort to implement and support this feature and likelihood of future changes, we're going to roll this into GP Randomizer.

@DamianSmith85
Copy link

DamianSmith85 commented May 26, 2023

Having issues with multipage form using this updated script.

The final page break field is sometimes called in upon refresh and I receive duplicate "Next" buttons.
The form cannot be completed due to this. It's a 50/50 whether it gets called in and breaks the form.

See below, should only be 8 questions being called in, but the random page break at the start sets it as 9.

The page break ID (46) is not included in the array:
new GFRandomFields( 4, 8, array( 3, 9, 7, 5, 18, 19, 20, 22, 29, 30, 31, 32, 33, 34, 35, 36 ), true );

Screenshot 2023-05-26 at 13 50 37 Screenshot 2023-05-26 at 14 27 33

@spivurno
Copy link
Contributor Author

spivurno commented May 26, 2023

@DamianSmith85 Drop us a line via support and we'll be happy to dig in. 🙂

PS – You'll need an Advanced or Pro license to receive snippet support.

@spivurno spivurno force-pushed the dave/add/better-pagination-support branch from 5379465 to 14dd9f3 Compare October 7, 2023 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants