Skip to content

Forms: migrate form fields to inner blocks - #43765

Merged
talldan merged 105 commits into
trunkfrom
update/migrate-form-fields-to-inner-blocks
Jun 5, 2025
Merged

talldan merged 105 commits into
trunkfrom
update/migrate-form-fields-to-inner-blocks

Conversation

@talldan

@talldan talldan commented Jun 4, 2025 •

Copy link
Copy Markdown
Contributor

Note: This is the second attempt at this PR, the first attempt was #42890, but was reverted

JETPACK-262

Fixes #42358

⚠️ This PR is now the sole source of truth for both adding new base form field blocks and migrating fields to them ⚠️

Proposed changes:

  • Add new base blocks for form fields:
    • Input
    • Label
    • Option
    • Options
  • Migrate all form fields to use new base blocks
    • File field is pending and will be updated to inner blocks in due course
  • Fixes for various minor forms bugs on trunk e.g. undo loops, minor style conflicts etc
  • Change consent and checkbox fields to share option styles not label/input styles for better consistency across fields

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

No changes.

Testing instructions:

General Notes

  • Please test undo and redo actions throughout all sequences. A number of improvements in this PR specifically enhance stability during these interactions
  • As this PR is still under active development and testing, these test instructions may need to evolve over time.

  1. 🧱 Field Insertion & Pasting

Goal: Confirm all form field blocks insert and behave as expected.

  • Insert each of the following field types via the block inserter:
    • Text, Name, Email, Number, Website, Phone, Multiline (Textarea)
    • Dropdown
    • Checkbox, Terms Consent
    • Single Choice (Radio), Multiple Choice (Checkbox),
    • Date Picker
  • Paste a field from one form into another.
  • Confirm all fields look correct, show relevant block controls, and function as expected.

⸻

  1. 🎨 Styling: Inputs, Labels, and Options

Goal: Confirm block and global styles apply and override correctly.

  • Apply styles via Global Styles (site editor).
  • Apply per-block styles using the block inspector.
  • Confirm styles render consistently in both the editor and frontend.
  • Test toggling individual styles on/off and reapplying.

⸻

  1. 🔁 Style Syncing Between Fields

Goal: Verify how styles are shared across synced fields of similar types.

  • Update a style on one synced field (e.g., font size or text color for an input field).
  • Confirm other synced input fields update accordingly.
  • Opt a field out of syncing and confirm it no longer updates.
  • Insert a new field and confirm it inherits current synced styles.
  • Paste a field from another form into a synced form and observe behavior.

⸻

  1. 🔀 Field Transforms

Goal: Ensure transforming between field types behaves as expected.

  • Transform fields (e.g., Name → Email, Text → Phone).
  • Confirm that styles and attributes are preserved only when appropriate.
  • Confirm that irrelevant attributes (like a "Name" label value when transforming to an Email field) are discarded.

⸻

  1. 🧩 Form Variations & Patterns

Goal: Ensure all form patterns insert correctly and render well.

Test inserting:

  • Contact Form
  • RSVP Form
  • Registration Form
  • Appointment Form
  • Feedback Form
  • Lead Capture Form
  • Salesforce Lead Form

Verify:

  • The default structure is valid and editable.
  • Labels, placeholders, and field types are appropriate.

⸻

  1. ✨ Style Variants

Goal: Validate style variations and layout combinations.

Insert:

  • Outlined Style Form
  • Animated Style Form

For both, test:

  • Base version
  • Version with field customizations
  • Upgrading from trunk form to refactor form
  • Confirm styles work.
  • Test columns and responsive behavior.

⸻

  1. 📦 Field Nesting

Goal: Confirm fields can be used within layout blocks.

  • Nest fields inside:
    • Group blocks
    • Columns
  • Confirm style syncing still works across nesting levels.
  • Check alignment and spacing behave as expected.

⸻

  1. 🪄 Automatic Form Wrapping

Goal: Ensure orphaned fields are auto-wrapped in a Form block.

  • Insert a field outside any form block.
  • Paste one or more fields into a blank page.
  • Confirm automatic wrapping behavior.
  • Save and verify layout remains valid.

⸻

  1. ⚙️ Required Field Settings

Goal: Validate required state control across all field types.

  • Toggle required setting for fields via field and inner blocks' block toolbars
  • Confirm required indicator displays appropriately.
  • Add custom required text and check that it renders.
  • Disable the required setting and confirm the indicator disappears.

⸻

  1. 🧪 Deprecations & Migrations

Goal: Confirm legacy forms upgrade smoothly.

  • On trunk, create a post containing all field types and apply styling.
  • Switch to the PR branch.

Confirm:

  • Legacy form still displays correctly on the frontend
  • No block validation errors in editor
  • Fields are migrated to inner block structure
  • Styling remains intact
  • Save the post and confirm the frontend still matches.

⸻

  1. 🌐 Additional Coverage

🧑‍🦯 Keyboard Accessibility

  • Tab through all form fields and verify correct focus behavior.
  • Ensure field labels are associated correctly (label-input relationships).

📱 Mobile Responsiveness

  • Test forms on small screens (phone/tablet viewports).
  • Confirm layouts stack properly and remain usable.

↔️ RTL Language Support

Switch the site language to RTL (e.g., Hebrew, Arabic).

Check that:

  • Layouts flip direction as expected
  • Labels and fields align correctly

♻️ Reusable Blocks

  • Save a form or field group as a reusable block.
  • Insert it into another post.
  • Confirm editing and layout integrity.

⚙️ Editor Performance

  • Insert lots of fields (30+).
  • Check for lag or editor slowdown during typing and style changes.

🌍 Multilingual / i18n Support

  • Switch site language.
  • Confirm labels, placeholders, and help texts are translatable and update correctly.

aaronrobertshaw and others added 30 commits June 4, 2025 13:59
Introduces foundational form field blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

These blocks will be reused across all field types using inner blocks.
- Prevents adding bulk changes when syncing blocks to the undo stack
- Correctly determines the parent field block for option blocks to check
  if syncing is enabled
- Correctly find all option blocks regardless of whether they are a
  field's direct child, e.g. consent, or nested within an options block
  e.g. single/multiple choice fields.
This is an enhancement over trunk however the is some work required to
make this actually work, especially given the shortcode rendering on the
frontend. For the time being this support will explicitly be opted out
of. It can be revisited when the benefit justifies the additional
complexity and work.
Updates legacy form field blocks to use shared inner blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

This commit also updates the registration of form blocks so the new
shared blocks are available in the editor.
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
* Refactor and update form field syncing.

- Use a parent react context provider as the source of truth instead of an
arbitrary sibling block.
- Perform a deep equality check before syncing to prevent against spurious
updates.

* When updating the block own attributes, mark the change as not persistent so that the user can undo

* Prime the previousOwnAttributes value so that we avoid updating syncedAttributes unnecessarily

* Update inline docs

* Prime the synced attributes when they are initially unset

* Fix syncing of styles across checkbox and consent options

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
…43027)

* Forms: Fix error thrown in previews for synced form fields

* Clean up

* Rename the context type stuff
…ne 'class' attribute on the extra_attrs array
@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jun 4, 2025
@github-actions

github-actions Bot commented Jun 4, 2025 •

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: July 1, 2025
    • Code freeze: June 30, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 4, 2025
@talldan talldan added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. Enhancement [Status] In Progress and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jun 4, 2025
@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jun 4, 2025
@jp-launch-control

jp-launch-control Bot commented Jun 4, 2025 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 8 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/contact-form/class-contact-form-field.php 516/862 (59.86%) 4.46% 61 💔
projects/packages/forms/src/contact-form/class-contact-form.php 560/917 (61.07%) -4.08% 59 💔
projects/packages/forms/src/contact-form/class-contact-form-plugin.php 411/1013 (40.57%) 7.51% 15 💔
projects/packages/forms/src/blocks/contact-form/variation-picker.js 0/24 (0.00%) 0.00% 2 ❤️‍🩹
projects/packages/forms/src/blocks/contact-form/util/form.js 0/20 (0.00%) 0.00% 1 ❤️‍🩹

88 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/packages/forms/src/blocks/deprecated/field-option-checkbox/index.js 0/4 (0.00%) 💔
projects/packages/forms/src/blocks/deprecated/field-option-radio/index.js 0/4 (0.00%) 💔
projects/packages/forms/src/blocks/field-checkbox/deprecated.js 0/3 (0.00%) 💔
projects/packages/forms/src/blocks/field-checkbox/edit.js 0/16 (0.00%) 💔
projects/packages/forms/src/blocks/field-checkbox/index.js 0/2 (0.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

…tions fields to select dropdown (#43789)

* Enhance field-select transformation by adding default placeholder for input block if none exists. Update console logs for debugging input attributes in edit.js. Refactor createTextFieldInnerBlocks to ensure non-mutating placeholder assignment during transformation.

* Refactor createTextFieldInnerBlocks to avoid mutating input attributes by destructuring them. This ensures a non-mutating approach when transforming to a select field, maintaining the integrity of the original block attributes.
@talldan talldan added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label Jun 5, 2025
talldan added 2 commits June 5, 2025 10:55
* Fix confusion over label/defaultLabel/placeholder

* Remove requiredText prop which does not exist

* Change standalone checkbox label placeholder back to Add Label...

* Fix variation textarea labels, which were accidentally changed to Message from Other Details
@talldan
talldan merged commit 458d65e into trunk Jun 5, 2025
@talldan
talldan deleted the update/migrate-form-fields-to-inner-blocks branch June 5, 2025 06:54
@github-actions github-actions Bot added this to the jetpack/14.8 milestone Jun 5, 2025
mikestottuk pushed a commit that referenced this pull request Jun 26, 2025
---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Form Form block (also see Form package label) Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. [Feature] Forms [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forms: Migrate form fields to inner blocks

4 participants