Skip to content

Forms: Add asset pipeline and style support for custom fields#47930

Open
enejb wants to merge 4 commits intoadd/form-fields-label-dashboardfrom
add/form-fields-asset-pipeline
Open

Forms: Add asset pipeline and style support for custom fields#47930
enejb wants to merge 4 commits intoadd/form-fields-label-dashboardfrom
add/form-fields-asset-pipeline

Conversation

@enejb
Copy link
Copy Markdown
Member

@enejb enejb commented Apr 3, 2026

Fixes #

Proposed changes

Adds style support and convention-over-configuration asset discovery to the custom form field registry:

  • Style support in field registry - Add editor_style, view_style, and dashboard_style registration alongside existing script support, with corresponding _deps and _ver options for each.
  • Convention-over-configuration asset discovery - When plugin_file is provided, assets are automatically resolved from conventional paths (build/index.js, build/editor-style.css, build/view.js, build/view-style.css, src/dashboard.js, build/dashboard-style.css). Dependencies and versions are loaded from build/index.asset.php. Individual assets can be overridden or disabled (set to false).
  • Editor styles via register_block_type - Editor stylesheets are registered through register_block_type() block args (editor_style) rather than direct wp_enqueue_style, ensuring styles load correctly inside the block editor iframe.
  • View and dashboard style enqueuing - View styles are enqueued during field rendering; dashboard styles are enqueued alongside dashboard scripts.
  • Docs update - Rewrites custom-fields.md into a template-driven format with LLM prompt template, file templates for all field components, webpack configuration, build instructions, and an emoji rating worked example.

Other information

This is PR 4 of 5 in a stacked PR series adding custom field extensibility to Jetpack Forms:

PR Focus
#47931 PR 1: PHP foundation (registry, rendering, validation)
#47932 PR 2: JS/Editor API (block registration, editor integration)
#47933 PR 3: Label block, dashboard integration, Interactivity API
#47930 PR 4: Asset pipeline & style support (this PR)
#47929 PR 5: Documentation & changelog
  • Generate changelog entries for this PR (using AI).

Related product discussion/links

  • Part of the Jetpack Forms custom fields extensibility project.

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

No changes to tracked data or activity.

Testing instructions

  1. Style registration defaults - Confirm the registry now accepts editor_style, view_style, and dashboard_style arguments with corresponding _deps and _ver options.

  2. Convention-over-configuration asset resolution - Create a test custom field plugin with plugin_file => __FILE__ and place files at the conventional paths (build/index.js, build/editor-style.css, build/view-style.css). Verify the registry auto-discovers and registers them without explicit URL configuration. Verify setting an asset to false disables it.

  3. Editor styles in iframe - Register a custom field with an editor_style. Open the block editor and confirm the stylesheet loads inside the editor iframe (inspect the iframe document for the <link> tag with handle jetpack-forms-field-{type}-editor).

  4. View style enqueuing - Add a custom field with a view_style to a form. View the form on the frontend and confirm the stylesheet is enqueued (check page source for the style handle jetpack-forms-field-{type}-view).

  5. Dashboard style enqueuing - Register a custom field with a dashboard_style. Open the Jetpack Forms responses page and confirm the stylesheet is loaded.

  6. Explicit override - Register a field with both plugin_file and an explicit editor_script URL. Verify the explicit URL takes precedence over convention-based resolution.

  7. Asset file loading - Place a build/index.asset.php in the plugin directory returning custom dependencies and version. Verify these are used for the editor script registration instead of defaults.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

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/form-fields-asset-pipeline branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/form-fields-asset-pipeline

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

github-actions bot commented Apr 3, 2026

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!

@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 Apr 3, 2026
enejb and others added 4 commits April 3, 2026 11:09
Add the ability to register editor, view, and dashboard styles for custom
form fields, mirroring the existing script registration pattern. This allows
custom field plugins to provide CSS/SCSS styles that are automatically
enqueued in the appropriate contexts.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add plugin_file parameter to register_jetpack_form_field() that auto-resolves
asset paths from conventional locations (build/index.js, build/editor-style.css,
build/view.js, build/view-style.css, src/dashboard.js). Dependencies and versions
are loaded from build/index.asset.php when available.

This simplifies field registration from verbose explicit paths to just:
'plugin_file' => __FILE__

Individual assets can be disabled (set to false) or overridden with custom paths.

Also updates documentation with template-based guide for creating new fields.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move editor style registration from wp_enqueue_style to register_block_type
  with editor_style parameter, ensuring styles load in block editor iframe
- Add comprehensive LLM prompt template to documentation for AI-assisted
  field creation, covering edge cases, accessibility, and best practices
- Include example prompts for star rating, signature, and date range fields

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs [Feature] Contact Form [Package] Forms [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant