Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inputs: Fix validation on programmatic value change#12892

Merged
danielchalmers merged 13 commits into
MudBlazor:devfrom
redgp0g:fix/form-validation-not-reevaluated-issue12012
Apr 8, 2026
Merged

Inputs: Fix validation on programmatic value change#12892
danielchalmers merged 13 commits into
MudBlazor:devfrom
redgp0g:fix/form-validation-not-reevaluated-issue12012

Conversation

@redgp0g

@redgp0g redgp0g commented Mar 24, 2026

Copy link
Copy Markdown
Contributor
video.mp4

Checklist:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests

- Create view and unit test to make sure the error message will show after updating the input value via programation
- Fix the MudBaseInput OnValueParameterChangedAsync to trigger the FiedlChange and BeginValidateAsync fixing the issue MudBlazor#12012
Copilot AI review requested due to automatic review settings March 24, 2026 13:29
@mudbot mudbot Bot changed the title MudBaseInput: fix re-evaluate input on change value with code Inputs: Fix validation on programmatic value change Mar 24, 2026
@mudbot mudbot Bot added the bug Unexpected behavior or functionality not working as intended label Mar 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a regression where MudBaseInput did not re-evaluate validation state when the bound Value parameter is updated programmatically (#12012), ensuring form errors clear/reappear appropriately after code-driven updates.

Changes:

  • Trigger FieldChanged + BeginValidateAsync when Value changes via parameter updates in MudBaseInput.
  • Add a unit test to validate error state transitions when Value is set via parameter binding.
  • Add a UnitTests.Viewer repro component demonstrating the programmatic update scenario with FluentValidation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/MudBlazor/Base/MudBaseInput.cs Revalidates and notifies form on parent-driven Value parameter changes.
src/MudBlazor.UnitTests/Components/FormTests.cs Adds regression test for clearing/restoring validation errors after programmatic value updates.
src/MudBlazor.UnitTests.Viewer/TestComponents/Form/FormValidationErrorClearedOnProgrammaticValueChangeTest.razor Adds a viewer repro component for the reported issue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/MudBlazor/Base/MudBaseInput.cs Outdated
Comment thread src/MudBlazor.UnitTests/Components/FormTests.cs
@redgp0g

redgp0g commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

@versile2 what do you think?

@versile2

Copy link
Copy Markdown
Contributor

@versile2 what do you think?

I think this part of the code base is not my expertise and I do not have adequate time to review/learn it. I believe @ScarletKuro is probably the most knowledgeable here.

@ScarletKuro

ScarletKuro commented Mar 25, 2026

Copy link
Copy Markdown
Member

I think this part of the code base is not my expertise and I do not have adequate time to review/learn it. I believe @ScarletKuro is probably the most knowledgeable here.

I don’t like the use of IsChildOriginatedChange here. We don’t use it and even try to avoid it, it was mainly introduced to cover external use cases and back then I thought it was really good idea to distinguish the source, but now I think If you need to distinguish whether a change was propagated from a parent update or originated within the component itself, it feels like a band-aid solution.
In my opinion, we should strive for validation to run consistently whenever a value changes, regardless of the source. The origin of the change shouldn’t matter.
I would even consider removing IsChildOriginatedChange in future, since we don’t use it ourselves. The parameter-state is niche, it's barely used outside of our team and Mud, since unfortunately it’s tied to Mud. I wish it were a standalone NuGet package usable across different UI frameworks, the code itself is actually independent. And in that case, it might make more sense to have it.
I’ve also noticed that AI tends to really love to use it to get things done quickly, but that often leads away from a proper architectural solution.

Feel free to prove me wrong whatever it's really necessary here.

@redgp0g

redgp0g commented Mar 28, 2026

Copy link
Copy Markdown
Contributor Author

IsChildOriginatedChange

I totally agree with removing the IsChildOriginatedChange for validation, I actually didn't notice the reason of using it as AI used it, sorry for that, next time I will take a better look.
About removing the IsChildOriginatedChange in the future, I don't have too much deep knowledge about the project, but I went throught some files and really think that could be a good idea, if I could help with it and learn a little bit more

Refactor field change notification to trigger only after the field has been touched.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danielchalmers danielchalmers merged commit 86c67b7 into MudBlazor:dev Apr 8, 2026
17 of 18 checks passed
@danielchalmers

Copy link
Copy Markdown
Member

Thank you!

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

Labels

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants