-
Couldn't load subscription status.
- Fork 1
feat(ngx-forms): added ngxFormsErrorsCustomErrorMessages input for per-instance error message override #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ngx-forms): added ngxFormsErrorsCustomErrorMessages input for per-instance error message override #449
Conversation
…rride global error messages on a per-control basis, enabling context-specific wording and dynamic translations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, @WHeirstrate any opinions?
| /** | ||
| * Custom error messages to override default ones | ||
| */ | ||
| private _customErrorMessages: Record<string, string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of the sudden underscore notation. I'd recommend changing the name of either the setter below or this property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will rename it to customMessages
|
Also: don't forget to update the docs! 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead 🙂
Added
ngxFormsErrorsCustomErrorMessagesinput to override global error messageson a per-control basis, enabling context-specific wording and dynamic translations.
Description:
This PR introduces a new optional input,
ngxFormsErrorsCustomErrorMessages, to thengxFormsErrorsdirective.It allows developers to provide custom error message overrides per form control instance while keeping the global defaults defined in
NgxFormsErrorsConfigurationToken.With this change, the directive now:
ngxFormsErrorsCustomErrorMessagesinput.<p>tag rendering.Why this change is needed
Previously, error messages were entirely defined at a global level through
NgxFormsErrorsConfigurationToken.errors. This meant:Example scenarios that were impossible before and are now supported:
Different messages for the same error key
invalidURL):Dynamic translations or variable interpolation
inputMinValue:Implementation details
During error rendering (
handleComponentRender/handleNoComponentFlow), the directive now:Retrieves
errorKeysfromgetErrors.Maps each key to either the custom message (if provided) or the default message from config.
This logic is applied consistently whether using a provided error component or the built-in paragraph fallback.
Backward compatibility
Usage examples:
Requirements