From 6fa4a613882b4abf19b232c2acf99ec074e05983 Mon Sep 17 00:00:00 2001 From: jojohoch <joachim.hoch@iqb.hu-berlin.de> Date: Wed, 22 Sep 2021 11:12:30 +0200 Subject: [PATCH] [player] Add pattern validation for text field --- .../validation-message/validation-message.component.html | 4 ++++ .../validation-message/validation-message.component.ts | 7 +++++++ projects/player/src/assets/i18n/de.json | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/projects/player/src/app/components/validation-message/validation-message.component.html b/projects/player/src/app/components/validation-message/validation-message.component.html index dae70ccf6..acfd5d66d 100644 --- a/projects/player/src/app/components/validation-message/validation-message.component.html +++ b/projects/player/src/app/components/validation-message/validation-message.component.html @@ -15,4 +15,8 @@ [ngClass]="{'dynamic-validation-message' : elementModel.dynamicPositioning}" > {{maxLengthWarnMessage}} </mat-error> + <mat-error *ngIf="formElementControl.errors?.pattern" + [ngClass]="{'dynamic-validation-message' : elementModel.dynamicPositioning}" > + {{patternMessage}} + </mat-error> </ng-container> diff --git a/projects/player/src/app/components/validation-message/validation-message.component.ts b/projects/player/src/app/components/validation-message/validation-message.component.ts index 5cbf0e8c3..b6a88c022 100644 --- a/projects/player/src/app/components/validation-message/validation-message.component.ts +++ b/projects/player/src/app/components/validation-message/validation-message.component.ts @@ -23,6 +23,7 @@ export class ValidationMessageComponent implements OnInit { requiredTrueMessage!: string; minLengthWarnMessage!: string; maxLengthWarnMessage!: string; + patternMessage!: string; constructor(private formService: FormService, private translateService: TranslateService) {} @@ -51,6 +52,9 @@ export class ValidationMessageComponent implements OnInit { if (this.elementModel.maxLength) { validators.push(Validators.maxLength(<number> this.elementModel.maxLength)); } + if (this.elementModel.pattern) { + validators.push(Validators.pattern(<string> this.elementModel.pattern)); + } return validators; } @@ -66,5 +70,8 @@ export class ValidationMessageComponent implements OnInit { this.maxLengthWarnMessage = (this.elementModel as TextFieldElement).maxWarnMessage || this.translateService.instant('validators.inputTooLong'); + + this.patternMessage = (this.elementModel as TextFieldElement).patternWarnMessage || + this.translateService.instant('validators.wrongPattern'); } } diff --git a/projects/player/src/assets/i18n/de.json b/projects/player/src/assets/i18n/de.json index 55da88d07..049ea0b40 100644 --- a/projects/player/src/assets/i18n/de.json +++ b/projects/player/src/assets/i18n/de.json @@ -7,7 +7,8 @@ "inputRequired": "Eingabe erforderlich", "inputRequiredTrue": "Ankreuzen erforderlich", "inputTooShort": "Eingabe zu kurz", - "inputTooLong": "Eingabe zu lang" + "inputTooLong": "Eingabe zu lang", + "wrongPattern": "Eingabe enthält falsche Zeichen" }, "dialogTitle": { "wrongUnitDefinitionType": "Falscher Unit-Definition-Type", -- GitLab