Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,17 @@ export const DEFAULT_ERROR_STATE_MATCHER: DynamicErrorMessagesMatcher =
};
```

You can also set an error matcher on a per control basis by assigning it under the `additional` field:
```ts
new DynamicInputModel({
id: "sampleInput",
label: "Sample Input",
additional: {
errorStateMatcher: myCustomErrorMessagesMatcher
}
})
```

Please note here that NG Dynamic Forms always assumes both the control being invalid and error messages being defined on the model
as a fixed precondition.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ export class DynamicFormValidationService {
control.updateValueAndValidity();
}

showErrorMessages(control: AbstractControl, model: DynamicFormControlModel, hasFocus: boolean): boolean {

const precondition = control.invalid && model.hasErrorMessages;
const matcher = this._DYNAMIC_ERROR_MESSAGES_MATCHER ? this._DYNAMIC_ERROR_MESSAGES_MATCHER(control, model, hasFocus) :
DEFAULT_ERROR_STATE_MATCHER(control, model, hasFocus);

return precondition && matcher;
}
showErrorMessages(control: AbstractControl, model: DynamicFormControlModel, hasFocus: boolean): boolean {
const precondition = control.invalid && model.hasErrorMessages;

const matcher =
model["getAdditional"] !== undefined && model["getAdditional"]("errorStateMatcher")
? model["getAdditional"]("errorStateMatcher")
: this._DYNAMIC_ERROR_MESSAGES_MATCHER
? this._DYNAMIC_ERROR_MESSAGES_MATCHER
: DEFAULT_ERROR_STATE_MATCHER;

return precondition && matcher(control, model, hasFocus);
}

parseErrorMessageConfig(template: string, model: DynamicFormControlModel, error: any = null): string {

Expand Down