Skip to content

Fix validation classes#83

Merged
albx merged 5 commits intomainfrom
bug/59-fix-validation-classes
Feb 26, 2026
Merged

Fix validation classes#83
albx merged 5 commits intomainfrom
bug/59-fix-validation-classes

Conversation

@albx
Copy link
Owner

@albx albx commented Feb 20, 2026

This pull request introduces improved validation styling and logic for form components in the BitBlazor library. It adds dynamic CSS class assignment for validation states, ensures correct cleanup of event handlers via IDisposable, and updates tests to verify the new validation behaviors. These changes provide immediate and clear feedback to users about the validity of form fields.

Validation logic and styling improvements:

  • Added dynamic assignment of validation CSS classes (is-invalid, just-validate-success-field) to input fields in BitFormComponentBase<T>, updating them in response to validation state changes. This includes subscribing to OnValidationStateChanged and providing helper methods for adding the appropriate classes. (src/BitBlazor/Form/BitFormComponentBase.cs) [1] [2] [3]
  • Updated the validation message rendering to use the just-validate-error-label CSS class for consistency with new validation styles. (src/BitBlazor/Form/BitFormComponentBase.cs)
  • Added the AddValidationCssClass method to the CSS class computation for all relevant form input components, including Checkbox, SelectField, and Toggle, ensuring validation classes are reflected in the rendered HTML. (src/BitBlazor/Form/BitInputFieldBase.cs, src/BitBlazor/Form/Checkbox/BitCheckbox.razor, src/BitBlazor/Form/Checkbox/BitCheckbox.razor.cs, src/BitBlazor/Form/SelectField/BitSelectField.razor, src/BitBlazor/Form/SelectField/BitSelectField.razor.cs, src/BitBlazor/Form/Toggle/BitToggle.razor, src/BitBlazor/Form/Toggle/BitToggle.razor.cs) [1] [2] [3] [4] [5] [6] [7]

Resource cleanup and lifecycle management:

  • Implemented the IDisposable pattern in BitFormComponentBase<T> to detach event handlers and prevent memory leaks. (src/BitBlazor/Form/BitFormComponentBase.cs) [1] [2]

Testing enhancements:

  • Added comprehensive tests to verify the correct application of validation CSS classes and validation messages for Checkbox and Datepicker components, including scenarios for valid, invalid, and pristine fields. (tests/BitBlazor.Test/Form/Checkbox/BitCheckboxTest.Rendering.razor, tests/BitBlazor.Test/Form/Datepicker/BitDatepickerTest.Rendering.razor, tests/BitBlazor.Test/Form/NumberField/BitNumberFieldTest.Rendering.razor) [1] [2] [3] [4] [5]

@albx albx linked an issue Feb 20, 2026 that may be closed by this pull request
@albx albx marked this pull request as ready for review February 24, 2026 21:25
@albx albx requested a review from Copilot February 24, 2026 21:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds dynamic validation styling to BitBlazor form components by automatically applying CSS classes based on validation state. It includes proper resource cleanup via IDisposable, comprehensive test coverage, and a complete sample application demonstrating the features with ASP.NET Core Identity integration.

Changes:

  • Added dynamic validation CSS class assignment ("is-invalid" and "just-validate-success-field") to form components
  • Implemented IDisposable pattern for proper event handler cleanup in BitFormComponentBase
  • Added extensive validation tests for all major form components

Reviewed changes

Copilot reviewed 100 out of 146 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/BitBlazor/Form/BitFormComponentBase.cs Core validation logic with event subscription, CSS class management, and IDisposable implementation
src/BitBlazor/Form/BitInputFieldBase.cs Integration of validation CSS classes into input field rendering
src/BitBlazor/Form/Checkbox/BitCheckbox.* Added validation CSS class support to checkbox component
src/BitBlazor/Form/SelectField/BitSelectField.* Added validation CSS class support to select component
src/BitBlazor/Form/Toggle/BitToggle.* Added validation CSS class support to toggle component
src/BitBlazor/Form/Radio/BitRadioGroup.razor.cs Updated validation message CSS class
tests/BitBlazor.Test/**/*.Rendering.razor Comprehensive validation tests for form components
tests/BitBlazor.Test/_Imports.razor Added Microsoft.AspNetCore.Components.Forms using directive
samples/** Complete sample application with Identity integration
BitBlazor.sln Added sample projects to solution
Files not reviewed (1)
  • samples/BitBlazor.Sample/BitBlazor.Sample/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs: Language not supported

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

@albx albx merged commit 22814c6 into main Feb 26, 2026
5 checks passed
@albx albx deleted the bug/59-fix-validation-classes branch February 26, 2026 06:58
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.

[BUG] Fix validation classes

2 participants