From 3ab6538d2a71db87cdc1941f92e4dd4a08b4704c Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Fri, 5 Jul 2024 19:15:07 +0300 Subject: [PATCH 1/2] work for #8508 [Angular] Pattern Input Mask - An invalid value is not always cleared --- .../src/questions/text.component.html | 2 +- .../src/questions/text.component.ts | 20 +++++++++- testCafe/questions/input_mask.ts | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/packages/survey-angular-ui/src/questions/text.component.html b/packages/survey-angular-ui/src/questions/text.component.html index 2a4892e9e9..63bc6f91f9 100644 --- a/packages/survey-angular-ui/src/questions/text.component.html +++ b/packages/survey-angular-ui/src/questions/text.component.html @@ -7,7 +7,7 @@
{{ value }}
- { + @ViewChild("inputElement") inputElementRef!: ElementRef; + get value(): string { return this.model.inputValue ?? ""; } + + blur(event: any): void { + this.model.onBlur(event); + this.updateInputDomElement(); + } + + updateInputDomElement(): void { + if (!!this.inputElementRef?.nativeElement) { + const control: any = this.inputElementRef.nativeElement; + if (!Helpers.isTwoValueEquals(this.value, control.value, false, true, false)) { + control.value = this.value; + } + } + } } AngularComponentFactory.Instance.registerComponent("text-question", TextQuestionComponent); \ No newline at end of file diff --git a/testCafe/questions/input_mask.ts b/testCafe/questions/input_mask.ts index 62e1b03754..5b348a1422 100644 --- a/testCafe/questions/input_mask.ts +++ b/testCafe/questions/input_mask.ts @@ -67,4 +67,41 @@ frameworks.forEach((framework) => { .expect(getCursor()).eql(6); }); + test("An invalid value is not always cleared", async (t) => { + await initSurvey(framework, { + focusFirstQuestionAutomatic: true, + pages: [ + { + name: "page1", + elements: [ + { + type: "text", + name: "question1", + maskType: "pattern", + maskSettings: { + pattern: "99999", + }, + }, + ], + }, + ], + }); + const emptyValue = "_____"; + + await t + .expect(Selector("input").value).eql(emptyValue) + + .pressKey("1 2 3 4") + .expect(Selector("input").value).eql("1234_") + + .pressKey("tab") + .expect(Selector("input").value).eql(emptyValue) + + .click("input") + .pressKey("1 2 3") + .expect(Selector("input").value).eql("123__") + + .pressKey("tab") + .expect(Selector("input").value).eql(emptyValue); + }); }); \ No newline at end of file From 88377370c5673eb29d8b58d592771438904f6ff0 Mon Sep 17 00:00:00 2001 From: OlgaLarina Date: Mon, 8 Jul 2024 10:00:08 +0300 Subject: [PATCH 2/2] work for #8508 update template --- packages/survey-angular-ui/src/questions/text.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/survey-angular-ui/src/questions/text.component.html b/packages/survey-angular-ui/src/questions/text.component.html index 63bc6f91f9..68c8cafd51 100644 --- a/packages/survey-angular-ui/src/questions/text.component.html +++ b/packages/survey-angular-ui/src/questions/text.component.html @@ -9,7 +9,7 @@