Skip to content

ChipField: Check chips for Required validation - #660

Open
redgp0g wants to merge 6 commits into
CodeBeamOrg:devfrom
redgp0g:fix/issue-284-chip-field-required
Open

redgp0g wants to merge 6 commits into
CodeBeamOrg:devfrom
redgp0g:fix/issue-284-chip-field-required

Conversation

@redgp0g

@redgp0g redgp0g commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

A required MudChipField was validated against the text typed in its input instead of its chips, so it showed the required error even when it had chips, and it accepted typed text that wasn't a chip yet as a value.

MudChipField has two validators registered in the form: the chip field itself, and the MudTextFieldExtended it renders inside (which is the one that displays the error). Both used the typed text to decide if there was a value. Changes:

  • MudChipField overrides HasValue to return true only when there is at least one chip, as suggested in the issue.
  • The inner text field is now ChipFieldTextField<T>, a small subclass of MudTextFieldExtended<T> whose HasValue asks the chip field if it has chips, so both validators agree. Without it, typing text cleared the error shown by the inner field, and validating the form again didn't bring it back because the Error parameter passed down didn't change.
  • ChipFieldTextField is public only because Razor can't render internal components, so I marked it [EditorBrowsable(Never)]. Happy to change the approach if you prefer another one.

I also fixed the script reference in the UnitTests.Viewer index.html: it pointed to MudExtensions.js, which doesn't exist (only MudExtensions.min.js is shipped), so mudBeforeInput was undefined and the delimiter didn't work in the Viewer.

Added ChipFieldRequiredTest and unit tests for: valid with chips, invalid without chips, invalid with typed text but no chips, error kept after typing, valid after adding a chip, no error on blur with chips, and the required marker staying visible.

Fixes #284

Before:

chip.error.mp4

After:

chip.fix.mp4

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.78%. Comparing base (7b71925) to head (323b240).
⚠️ Report is 3 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #660      +/-   ##
==========================================
+ Coverage   67.32%   67.78%   +0.45%     
==========================================
  Files         117      118       +1     
  Lines        8550     8554       +4     
  Branches     1510     1514       +4     
==========================================
+ Hits         5756     5798      +42     
+ Misses       2253     2227      -26     
+ Partials      541      529      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MudChipField - Required property should enforce the presence of chips

1 participant