From 30b0a60754d4d9144a2a82fda2ca307d558e9dd2 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 18 Aug 2023 12:04:20 +0300 Subject: [PATCH] survey.maxTextLength should not be applied fo text input type only fix #6750 --- src/question_text.ts | 4 ++++ tests/surveyquestiontests.ts | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/question_text.ts b/src/question_text.ts index b76de33172..d522bd875a 100644 --- a/src/question_text.ts +++ b/src/question_text.ts @@ -65,6 +65,10 @@ export class QuestionTextModel extends QuestionTextBase { this.step = undefined; } } + public getMaxLength(): any { + if(this.inputType !== "text") return null; + return super.getMaxLength(); + } public runCondition(values: HashTable, properties: HashTable) { super.runCondition(values, properties); if (!!this.minValueExpression || !!this.maxValueExpression) { diff --git a/tests/surveyquestiontests.ts b/tests/surveyquestiontests.ts index 50b8150699..32cc07c8a6 100644 --- a/tests/surveyquestiontests.ts +++ b/tests/surveyquestiontests.ts @@ -2435,7 +2435,7 @@ QUnit.test("question.clearIncorrectValues and choicesByUrl", function (assert) { ); }); -QUnit.test("questiontext.maxLength", function (assert) { +QUnit.test("questiontext.maxLength & make it works for text input type only, #6750", function (assert) { var survey = new SurveyModel(); var page = survey.addNewPage("p1"); var qText = new QuestionTextModel("q1"); @@ -2447,6 +2447,16 @@ QUnit.test("questiontext.maxLength", function (assert) { assert.equal(qText.getMaxLength(), null, "makes it undefined"); qText.maxLength = 5; assert.equal(qText.getMaxLength(), 5, "gets 5 from question"); + qText.maxLength = -1; + assert.equal(qText.getMaxLength(), 10, "get from survey again"); + qText.inputType = "date"; + assert.equal(qText.getMaxLength(), null, "input type is 'date'"); + qText.inputType = "number"; + assert.equal(qText.getMaxLength(), null, "input type is 'number'"); + qText.inputType = "color"; + assert.equal(qText.getMaxLength(), null, "input type is 'color'"); + qText.inputType = "text"; + assert.equal(qText.getMaxLength(), 10, "input type is 'text'"); }); QUnit.test("Display Current/Maximum Allowed Characters when a maximum length is defined for input fields", function (assert) {