Repository navigation
fix(form-validation-message): clear messages when controls return to pristine - #1446
iOvergaard wants to merge 4 commits into
Conversation
…pristine Form controls only dispatch VALID/INVALID while not pristine, so a control going back to pristine (form reset or programmatic) left its message on screen forever. Since pristine is a reflected attribute, observe it on the controls we currently show messages for and drop the message when the control becomes pristine again. Found during a holistic review of UUIFormControlMixin; pre-existing since v1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a long-standing UX bug in uui-form-validation-message where validation messages could remain visible after a control returns to pristine (e.g., via form.reset()), by detecting pristine transitions and clearing the corresponding messages locally in the message component.
Changes:
- Added a
MutationObserverto watchpristineattribute changes on controls currently associated with displayed validation messages, removing messages when controls become pristine again. - Updated the VALID/INVALID event handlers to refresh the observed control set whenever the message map changes.
- Added two tests covering message clearing on both
form.reset()and programmaticpristine = true.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/components/form-validation-message/form-validation-message.element.ts | Observe pristine attribute changes for currently-messaged controls and clear messages when they return to pristine. |
| src/components/form-validation-message/form-validation-message.test.ts | Adds regression tests ensuring messages clear on reset and when a control is set back to pristine. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
|
@nielslyngsoe this is trying to fix a latent bug where validation messages don't disappear if you "reset" the form. This works by observing the pristine attribute. Would you take a look and evaluate if this is something we ought to have in the UI library, please? |
| // back to pristine (e.g. on form reset) would leave its message behind. The `pristine` | ||
| // property is reflected, so we observe the attribute on controls we currently show | ||
| // messages for and remove them when they become pristine again. | ||
| private readonly _pristineObserver = new MutationObserver(entries => { |
There was a problem hiding this comment.
I think it would be more right if a FormControl fired a valid event when it gets reset(when Pristine gets set again, so we avoid having any external relation to the pristine attribute)
There was a problem hiding this comment.
Thanks Niels, that's simpler 👍 I've reworked it in 8604429. formResetCallback now dispatches valid, and the message element doesn't look at pristine at all any more.
I've kept it to the reset rather than any pristine = true, because your tests from #1479 pin that going pristine on its own reports nothing ("does not report Valid when going pristine again while still invalid"). If you'd rather have it in the pristine setter, those two tests flip, and in the CMS UmbFormControlValidator.reset() would then mark a UUI control as valid the moment it resets. Happy either way.
I merged main in first, since the mixin has moved a lot since July. All 1125 tests pass.
…ation-messages-on-form-reset
…clear A reset control is pristine, so it never reported its state again and uui-form-validation-message kept showing the old message. formResetCallback now dispatches a valid event, which the message element already handles, instead of the message element observing the pristine attribute. Setting pristine to true on its own still reports nothing, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1446.westeurope.azurestaticapps.net |



Summary
uui-form-validation-messagebuilds its message list fromvalid/invalidevents, but a form control that is reset goes back to pristine and never reports its state again. Its validation message stayed on screen afterform.reset().formResetCallbackin the form control mixin now dispatches avalidevent, which the message element already handles. The message element has no relation to thepristineattribute.pristine = trueon its own still reports nothing, as pinned by the existing mixin tests ("does not report Valid when going pristine again while still invalid").validas the last reported state, so a control that is valid after the reset doesn't report it twice, and touching an invalid control reportsinvalidagain.UUIFormControlMixin.How to test
uui-formwrapping a<form>with a requireduui-input, auui-form-validation-message, plus submit and reset buttons.Test plan
validon reset even while invalid (fails without the fix), and reportsinvalidagain when touched after a resetform-validation-message: the message clears onform.reset()(fails without the fix)tscand lint clean🤖 Generated with Claude Code