feat: Add native Angular forms validation support with conditional error messages #4875
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements native Angular reactive and template-driven forms validation support for DB-UX input components, enabling developers to use conditional validation messages that automatically show/hide based on FormControl validation state.
Problem
Previously, DB-UX input components only supported standard HTML validation attributes (
required
,min/max
, etc.) and ignored Angular FormControl validators. Developers had to implement custom validation message handling, missing out on Angular's powerful validation ecosystem and DB-UX's built-in validation styling.Solution
Enhanced Input Component
NgControl
injection to access FormControl validation stategetFormControlErrors()
andhasFormControlError(errorType)
methodshandleValidation()
to check both HTML and Angular validation errorsEnhanced Infotext Component
error
property for conditional display based on specific validation errorsshouldShow()
logic that checks parent input's FormControl stateUsage Pattern
The implementation enables the exact usage pattern requested in the issue:
Form Setup
Key Features
db-infotext
with anerror
attribute conditionally displays based on FormControl errorsValidators.required
,Validators.email
,Validators.minLength
, etc.semantic="critical"
for errors)Implementation Details
The solution uses Angular's post-build transformation system to inject FormControl integration without affecting other framework outputs (React, Vue, Stencil). The core Mitosis components remain framework-agnostic while Angular gets enhanced validation capabilities.
Documentation
Updated Angular documentation with comprehensive examples showing:
Fixes #3948.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.