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

(WIP) Forms: Update form field support for container block layouts #41805

Draft
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Feb 14, 2025

Fixes #41428

Remaining issues:

  • Form submission error/validation messages don't look great. I think there should be a block for the main error message so that users can style it and position it where they want (and possibly show multiple).
  • Button width settings don't work correctly in some (all?) layouts

Description

Makes blocks like Row, Stack, Grid, Group, Columns work within the Form block. Users can add field blocks within them and they should adopt the correct layout.

This allows for achieving layouts that weren't possible before (I guess without custom CSS?):

Two fields and a button in a row and a checkbox underneath. The fields are set to 'Grow', while the button doesn't:

Screenshot 2025-02-14 at 1 07 26 pm

Interesting grids

Screenshot 2025-02-14 at 1 24 53 pm

And probably more

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  • Go to '..'

@talldan talldan added [Block] Contact Form Form block (also see Contact Form label) [Package] Forms [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. labels Feb 14, 2025
@talldan talldan self-assigned this Feb 14, 2025
@@ -26,6 +26,7 @@ const FieldDefaults = {
supports: {
reusable: false,
html: false,
spacing: {},
Copy link
Contributor Author

@talldan talldan Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be needed to show the sizing controls in the Styles tab. 🤔

@github-actions github-actions bot added [Block] Button [Feature] Contact Form [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Feb 14, 2025
Copy link
Contributor

github-actions bot commented Feb 14, 2025

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 Team 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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? 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 semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for none scheduled (scheduled code freeze on undefined).

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 would need you to make some changes or provide some more details about your PR. Thank you! label Feb 14, 2025
}
isShownByDefault
>
<JetpackFieldWidth setAttributes={ setAttributes } width={ width } />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the width field to the styles tab, so that dimension controls (whether core's or jetpack's) are always in a consistent place.

I guess this might need some discussion, and particularly given all the other style controls are still in the settings tab.

Significance: patch
Type: fixed

Forms: fix column block width when used in the form block.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to update this

Comment on lines +310 to +357
/**
* Build the CSS for the child layout.
* This replicates part of the `wp_render_layout_support_flag` function from WordPress core.
* That function doesn't work for form fields due to the way they're rendered as shortcodes,
* while the core function will only generate and apply classnames for layout to html.
*
* @param array $layout - the block's `style.layout` attribute.
*
* @return string CSS for the child layout.
*/
private static function build_child_layout_css( $layout ) {
$css = '';

if ( ! $layout ) {
return $css;
}

$self_stretch = isset( $layout['selfStretch'] ) ? $layout['selfStretch'] : null;

if ( 'fixed' === $self_stretch && isset( $layout['flexSize'] ) ) {
$css .= 'flex-basis: ' . $layout['flexSize'] . ';';
$css .= 'box-sizing: border-box;';
} elseif ( 'fill' === $self_stretch ) {
$css .= 'flex-grow: 1;';
}

$column_start = isset( $layout['columnStart'] ) ? $layout['columnStart'] : null;
$column_span = isset( $layout['columnSpan'] ) ? $layout['columnSpan'] : null;
if ( $column_start && $column_span ) {
$css .= "grid-column: $column_start / span $column_span;";
} elseif ( $column_start ) {
$css .= "grid-column: $column_start;";
} elseif ( $column_span ) {
$css .= "grid-column: span $column_span;";
}

$row_start = isset( $layout['rowStart'] ) ? $layout['rowStart'] : null;
$row_span = isset( $layout['rowSpan'] ) ? $layout['rowSpan'] : null;
if ( $row_start && $row_span ) {
$css .= "grid-row: $row_start / span $row_span;";
} elseif ( $row_start ) {
$css .= "grid-row: $row_start;";
} elseif ( $row_span ) {
$css .= "grid-row: span $row_span;";
}

return $css;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unfortunate this is needed, but the positive of doing it this way vs. other things I've tried is that it's very easy to understand and super easy to fix any bugs. It doesn't rely on any tricks and isn't much code.

The other options were all too brittle.

@@ -89,7 +89,6 @@ public function __construct( $attributes, $content = null, $form = null ) {
'requiredtext' => null,
'options' => array(),
'id' => null,
'style' => null,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I accidentally deleted this. I'm not sure if it's used?

@enejb
Copy link
Member

enejb commented Feb 14, 2025

I tested this and it worked really well, it makes it a lot easier to create the complex form layouts in the editor now. Thank you for tackling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Button [Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forms: add layout support
2 participants