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"); +});