Skip to content

Fix: Programmatic required error does not work as expected on the toggle control#74952

Closed
jorgefilipecosta wants to merge 1 commit intotrunkfrom
fix/toggle-control-programatti-required-error-does-not-work-as-expected
Closed

Fix: Programmatic required error does not work as expected on the toggle control#74952
jorgefilipecosta wants to merge 1 commit intotrunkfrom
fix/toggle-control-programatti-required-error-does-not-work-as-expected

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta commented Jan 26, 2026

Fixes an issue reported by @oandregal where on toggle control the programmatic errors don't work as expected.
The cause was a timing bug where the Toggle field's validation error was not displayed after opening a previously collapsed card, even though the badge correctly showed the field count.
The solution was to change useEffect to useLayoutEffect in ValidatedToggleControl so the required attribute is set on the input before ControlWithError's effect reads validationMessage

Testing

  • Open Storybook at ?path=/story/dataviews-dataform--validation&args=layout:card-collapsible
  • Open the "Boolean Fields" card, then close it — badge shows "2 fields need attention"
  • Reopen the card — verify the Toggle error message now appears (on trunk it does not)
  • Verify checkbox and toggle group errors still display correctly
  • Toggle the control on/off to confirm it still functions

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Jan 26, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 26, 2026

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: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>

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

@github-actions
Copy link
Copy Markdown

Flaky tests detected in df5afe4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/21371001426
📝 Reported issues:

@SirLouen
Copy link
Copy Markdown
Member

Using useLayoutEffect for this feels a bit like a step backwards.

✅ I have tested it, and it's clearly solving this, but my question is:

Why don't we get to the root of the problem with the required not being passed?

I'm proposing an alternative here #74956 feel free to comment, I've recently started to dig in DataViews/DataForms so maybe I don't have full context.

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Thank you for the alternative fix @SirLouen, it seems a better solution I'm going to close this PR in favor of #74956.

@oandregal oandregal deleted the fix/toggle-control-programatti-required-error-does-not-work-as-expected branch January 27, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants