From e246e75fc0d5ed557cc3e24efed103d43fa8b266 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Thu, 25 Jan 2024 11:58:14 +0200 Subject: [PATCH] The maxLength property doesn't work for Password input fields fix #7728 --- src/question_text.ts | 2 +- tests/question_texttests.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/question_text.ts b/src/question_text.ts index b0ab0ad41e..debffae635 100644 --- a/src/question_text.ts +++ b/src/question_text.ts @@ -67,7 +67,7 @@ export class QuestionTextModel extends QuestionTextBase { } } public getMaxLength(): any { - if(this.inputType !== "text") return null; + if(!this.isTextInput) return null; return super.getMaxLength(); } public runCondition(values: HashTable, properties: HashTable) { diff --git a/tests/question_texttests.ts b/tests/question_texttests.ts index 860ad6017f..70d92ffc57 100644 --- a/tests/question_texttests.ts +++ b/tests/question_texttests.ts @@ -402,4 +402,16 @@ QUnit.test("Set empty text", function(assert) { QUnit.test("Text Question KeyHandler exists", function (assert) { const q = new QuestionTextModel("q1"); assert.ok(q["onTextKeyDownHandler"], "we need this handler for using in Survey Creator"); -}); \ No newline at end of file +}); +QUnit.test("Test maxLength & getMaxLength", function (assert) { + const q = new QuestionTextModel("q1"); + q.maxLength = 10; + assert.equal(q.isTextInput, true, "isTextInput - text"); + assert.equal(q.getMaxLength(), 10, "getMaxLength() - text"); + q.inputType = "color"; + assert.equal(q.isTextInput, false, "isTextInput - color"); + assert.equal(q.getMaxLength(), null, "getMaxLength() - color"); + q.inputType = "password"; + assert.equal(q.isTextInput, true, "isTextInput - password"); + assert.equal(q.getMaxLength(), 10, "getMaxLength() - password"); +});