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 =
1071
1071
};
1072
1072
```
1073
1073
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
+
1074
1085
Please note here that NG Dynamic Forms always assumes both the control being invalid and error messages being defined on the model
1075
1086
as a fixed precondition.
1076
1087
Original file line number Diff line number Diff line change @@ -136,14 +136,18 @@ export class DynamicFormValidationService {
136
136
control . updateValueAndValidity ( ) ;
137
137
}
138
138
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
+ typeof 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
+ }
147
151
148
152
parseErrorMessageConfig ( template : string , model : DynamicFormControlModel , error : any = null ) : string {
149
153
You can’t perform that action at this time.
0 commit comments