Skip to content

Forms: conditional logic (3/5) — apply in the browser - #50978

Open
enejb wants to merge 1 commit into
add/forms-conditional-logic-resolverfrom
add/forms-conditional-logic-frontend
Open

Forms: conditional logic (3/5) — apply in the browser#50978
enejb wants to merge 1 commit into
add/forms-conditional-logic-resolverfrom
add/forms-conditional-logic-frontend

Conversation

@enejb

@enejb enejb commented Jul 31, 2026

Copy link
Copy Markdown
Member

Part 3 of 5. This series splits #50938 into reviewable pieces. Each PR is based on the previous one, so the diff shown here is incremental.

  1. Forms: conditional logic (1/5) — vocabulary and feature flag #50976 — vocabulary and feature flag
  2. Forms: conditional logic (2/5) — the resolver, in JS and PHP #50977 — the resolver, in JS and PHP
  3. Forms: conditional logic (3/5) — apply in the browser #50978 — apply in the browser
  4. Forms: conditional logic (4/5) — server-side render and validation #50979 — server-side render and validation
  5. Forms: conditional logic (5/5) — the editor panel #50980 — the editor panel

Proposed changes

Part 3 of 5 splitting #50938. Wires the resolver into the front-end form so fields appear and disappear as the visitor answers, and skips hidden fields when validating.

  • Visibility is memoised per form rather than globally. Two forms on one page have their own rules and answers, and a single shared cache let one form's result satisfy the other's lookup.
  • Hidden fields use display: none as the base state, so a visitor with JavaScript or animations off still gets a correct form. The reveal animation is purely additive, scoped to conditional fields, and inside @media not (prefers-reduced-motion).

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

The server does not stamp conditional markup until part 4, so the easiest way to exercise this alone is the unit tests:

  • jetpack test js packages/formsconditional-visibility.test.js covers the cascade, the per-form isolation, and the hidden-field validation skip.

For a live check, enable the flag and use a form whose fields already carry data-jp-conditional (or wait for part 4, which emits it):

  • Type into the field a rule depends on and confirm the dependent field appears/disappears immediately.
  • Confirm a hidden required field does not block submission.
  • With "Reduce motion" enabled in the OS, confirm the field still appears — just without the transition.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/forms-conditional-logic-frontend branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-conditional-logic-frontend

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Jul 31, 2026

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit 0cc8354, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for 0cc8354 is available.

Full summary · PHP report · JS report

Wire the resolver into the front-end form so fields appear and disappear as the
visitor answers, and skip hidden fields when validating.

Visibility is memoised per form rather than globally: two forms on one page have
their own rules and answers, and a single shared cache let one form's result
satisfy the other's lookup.

Hidden fields use `display: none` as the base state, so a visitor with
JavaScript or animations off still gets the right form. The reveal animation is
additive, scoped to conditional fields, and inside
`@media not (prefers-reduced-motion)`.

Checkbox normalisation keys off the control's actual type rather than the
field's declared one, so a consent field -- which renders as a checkbox but
declares 'consent' -- no longer reads as checked after the visitor unchecks it.

The context is also reconciled from the DOM on a bfcache restore, since neither
input nor change fires when the browser puts the visitor's values back, and
focus moves to the nearest visible control when the field being filled in is
hidden by a cascade.
@enejb
enejb force-pushed the add/forms-conditional-logic-resolver branch from c43767f to 0cc8354 Compare August 4, 2026 18:36
@enejb
enejb force-pushed the add/forms-conditional-logic-frontend branch from 5a56544 to cf7083a Compare August 4, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant