Skip to content

Conversation

@hbhalodia
Copy link
Contributor

What?

Closes #73330

Why?

  • When using modal and isValid is false, we still have apply button enabled, instead it should be disabled.

How?

  • Get isValid from useFormValidity custom hook and add disabled attribute in the button based on validity.

Testing Instructions

  1. Create a field with:
isValid: {
	required: true,
},
  1. In the form, set its layout to:
layout: {
	type: 'panel' as const,
	openAs: 'modal',
},
  1. Add it to a DataForm.
  2. Click to edit it.
  3. Don't fill in a value -- notice that an error message shows up below the field.
  4. Notice that you are now not able to click the Apply button, and validating the input.

Testing Instructions for Keyboard

  • None

Screenshots or screencast

Before After
Screenshot 2025-11-17 at 1 44 29 PM Screenshot 2025-11-17 at 1 44 03 PM

@github-actions
Copy link

github-actions bot commented Nov 17, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: hbhalodia <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: jimjasson <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@hbhalodia hbhalodia added [Type] Bug An existing feature does not function as intended [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Nov 17, 2025
@ntsekouras
Copy link
Contributor

👋 - Thanks for the PR. Can you add a changelog entry?

@hbhalodia
Copy link
Contributor Author

👋 - Thanks for the PR. Can you add a changelog entry?

Yes on it 👍

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ntsekouras ntsekouras enabled auto-merge (squash) November 17, 2025 09:20
@ntsekouras ntsekouras merged commit a200b02 into WordPress:trunk Nov 17, 2025
34 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 17, 2025
</Button>
<Button
variant="primary"
disabled={ ! isValid }
Copy link
Member

Choose a reason for hiding this comment

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

I'd like confirmation from @jameskoster and @mirka but, IIRC, this is not something we want. This prevents users from closing the modal unless all values are valid.

The rationale is that users may run into situations where they can't close the panel. Form example, a form that contains empty values and, once loaded, it couldn't be closed unless the user fills them all. DataForm doesn't handle saving, there's a consumer layer that needs to deal with that, and that'd a better point to handle this logic.

Additionally, even for saving a form, @mirka argued (failed to find the link, sorry), that it'd be better to let values to be submitted and the server respond.

With my current understanding, this would need to be reverted.

Copy link
Contributor

Choose a reason for hiding this comment

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

This prevents users from closing the modal unless all values are valid.

Isn't the cancel button enough?

Copy link
Member

Choose a reason for hiding this comment

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

Not exactly what I was looking for, but #71412 (comment) may be helpful to understand the rationale.

Copy link
Contributor

@ntsekouras ntsekouras Nov 17, 2025

Choose a reason for hiding this comment

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

Thanks for sharing @oandregal! It seems there is tons of context needed behind many things in these parts. Let's revert this.

Copy link
Member

Choose a reason for hiding this comment

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

Nik prepared a revert #73367 (just for context for folks coming to this thread)

Copy link
Member

Choose a reason for hiding this comment

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

Right, I think what we want here is a standard

and type="submit" button pattern. These two pieces are what prevent a form from submitting with invalid fields.

To be clear, we want to keep the submit button enabled so the form element can handle the blocking.

👍

@mirka I understand this is the flow we want for the component that uses DataForm. The case here is a bit different: DataForm is rendering a panel layout, that opens a modal to edit the values. The question is what happens with that modal's save button if some value is invalid.

Screen.Recording.2025-11-18.at.10.03.25.mov

Or are you saying that we should also use that flow for the modal?

I want to make sure there's clarity on this because my understanding was the opposite (we don't do anything special for the modal, just let user apply the values, and we handle it at the form level as you suggested).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is surprisingly complex haha. Since the modal doesn't submit the form trapping the user feels a bit intrusive, almost like not allowing them to tab away from an invalid field in the 'regular' layout.

That said, there are a few quirks with this approach. Observe the following video:

Screen.Recording.2025-11-18.at.10.35.50.mov

"Order" is a number input. There's no indication the letter-based value I input is invalid because of when we validate. Even if we visually indicate invalid fields when the modal is closed (which we should), that wouldn't capture this scenario because the invalid value is stripped meaning the field is no longer invalid. It feels like I was able to successfully set 'abc' as the Order. I suspect we'd need quite a bit of logic to make a flow like this not feel broken.

On the other hand, there are situations where trapping could lead to really awkward experiences. Imagine a form with a required "I agree to terms" checkbox. Once you open the modal it wouldn't be possible to close it until you check the option, effectively forcing the user to agree.

Neither approach seems perfect. It seems a case of choosing the 'safest' one.

Copy link
Member

Choose a reason for hiding this comment

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

Even if we visually indicate invalid fields when the modal is closed (which we should)

Yeah, this is also related to #72321

Copy link
Member

Choose a reason for hiding this comment

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

I'm demonstrating two patterns in #71282:

  • Prevent closing on an invalid form, no matter what.
  • Prevent closing on an invalid form, only when the user explicitly hits the save button.

What I've been suggesting is the latter ("Validate in modal" story).

Copy link
Member

Choose a reason for hiding this comment

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

@oandregal I discussed this with @jameskoster @jasmussen @fcoveram today, and we agreed on the "validate in modal" pattern in #71282. Some additional subtleties here are to disable shouldCloseOnClickOutside and isDismissable on the modal, to make the cancel intent more explicit.

We also considered disabling shouldCloseOnEsc, but we don't have a strong conviction about this one way or the other, as there are pros and cons. I think we can start by leaving it as is, and see how that works in practice.

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

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DataForm]: The ModalContent component doesn't properly check for fields validity

5 participants