File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
projects/ng-dynamic-forms/core/src/lib/service Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -1071,6 +1071,17 @@ export const DEFAULT_ERROR_STATE_MATCHER: DynamicErrorMessagesMatcher =
10711071 };
10721072```
10731073
1074+ You can also set an error matcher on a per control basis by assigning it under the ` additional ` field:
1075+ ``` ts
1076+ new DynamicInputModel ({
1077+ id: " sampleInput" ,
1078+ label: " Sample Input" ,
1079+ additional: {
1080+ errorStateMatcher: myCustomErrorMessagesMatcher
1081+ }
1082+ })
1083+ ```
1084+
10741085Please note here that NG Dynamic Forms always assumes both the control being invalid and error messages being defined on the model
10751086as a fixed precondition.
10761087
Original file line number Diff line number Diff line change @@ -136,14 +136,18 @@ export class DynamicFormValidationService {
136136 control . updateValueAndValidity ( ) ;
137137 }
138138
139- showErrorMessages ( control : AbstractControl , model : DynamicFormControlModel , hasFocus : boolean ) : boolean {
140-
141- const precondition = control . invalid && model . hasErrorMessages ;
142- const matcher = this . _DYNAMIC_ERROR_MESSAGES_MATCHER ? this . _DYNAMIC_ERROR_MESSAGES_MATCHER ( control , model , hasFocus ) :
143- DEFAULT_ERROR_STATE_MATCHER ( control , model , hasFocus ) ;
144-
145- return precondition && matcher ;
146- }
139+ showErrorMessages ( control : AbstractControl , model : DynamicFormControlModel , hasFocus : boolean ) : boolean {
140+ const precondition = control . invalid && model . hasErrorMessages ;
141+
142+ const matcher =
143+ model [ "getAdditional" ] !== undefined && model [ "getAdditional" ] ( "errorStateMatcher" )
144+ ? model [ "getAdditional" ] ( "errorStateMatcher" )
145+ : this . _DYNAMIC_ERROR_MESSAGES_MATCHER
146+ ? this . _DYNAMIC_ERROR_MESSAGES_MATCHER
147+ : DEFAULT_ERROR_STATE_MATCHER ;
148+
149+ return precondition && matcher ( control , model , hasFocus ) ;
150+ }
147151
148152 parseErrorMessageConfig ( template : string , model : DynamicFormControlModel , error : any = null ) : string {
149153
You can’t perform that action at this time.
0 commit comments