From 443768b7e87febd44b563099a4885398917f354c Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Wed, 21 Feb 2024 10:56:13 +0200 Subject: [PATCH] Single-Choice Matrix in Modern Theme - Rows receive the .sv-matrix__row--error class fix #7889 --- src/question_matrix.ts | 10 +++++----- tests/question_matrix_tests.ts | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/question_matrix.ts b/src/question_matrix.ts index 1696a90b7a..752d88ec90 100644 --- a/src/question_matrix.ts +++ b/src/question_matrix.ts @@ -451,7 +451,7 @@ export class QuestionMatrixModel return loc ? loc : this.emptyLocalizableString; } supportGoNextPageAutomatic(): boolean { - return this.isMouseDown === true && this.hasValuesInAllRows(); + return this.isMouseDown === true && this.hasValuesInAllRows(false); } private errorsInRow: HashTable; protected onCheckForErrors(errors: Array, isOnValueChanged: boolean): void { @@ -467,12 +467,12 @@ export class QuestionMatrixModel } } private hasErrorAllRowsRequired(): boolean { - return this.isAllRowRequired && !this.hasValuesInAllRows(); + return this.isAllRowRequired && !this.hasValuesInAllRows(true); } private hasErrorEachRowUnique(): boolean { return this.eachRowUnique && this.hasNonUniqueValueInRow(); } - private hasValuesInAllRows(): boolean { + private hasValuesInAllRows(addError: boolean): boolean { var rows = this.generatedVisibleRows; if (!rows) rows = this.visibleRows; if (!rows) return true; @@ -480,7 +480,7 @@ export class QuestionMatrixModel for (var i = 0; i < rows.length; i++) { const row = rows[i]; const hasValue = !this.isValueEmpty(row.value); - if(!hasValue) { + if(addError && !hasValue) { this.addErrorIntoRow(row); } res = res && hasValue; @@ -512,7 +512,7 @@ export class QuestionMatrixModel this.errorsInRow[row.name] = true; } protected getIsAnswered(): boolean { - return super.getIsAnswered() && this.hasValuesInAllRows(); + return super.getIsAnswered() && this.hasValuesInAllRows(false); } private createMatrixRow( item: ItemValue, diff --git a/tests/question_matrix_tests.ts b/tests/question_matrix_tests.ts index 3fa9aca4bf..daf043b64d 100644 --- a/tests/question_matrix_tests.ts +++ b/tests/question_matrix_tests.ts @@ -121,6 +121,30 @@ QUnit.test("matirix row, rowClasses property, eachRowUnique", function (assert) assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1) #2"); assert.equal(question.visibleRows[1].rowClasses, "row", "second row #2"); }); +QUnit.test("matirix row, rowClasses property, #7889", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "matrix", + name: "q1", + columns: ["col1", "col2"], + rows: ["row1", "row2", "row3"], + eachRowUnique: true, + }, + ], + }); + survey.css = { matrix: { row: "row", rowError: "row_error" } }; + const question = survey.getQuestionByName("q1"); + assert.ok(question.cssClasses.row, "Row class is not empty"); + assert.equal(question.hasErrorInRow(question.visibleRows[0]), false, "hasErrorInRow(0), #1"); + assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1), #2"); + assert.equal(question.hasErrorInRow(question.visibleRows[2]), false, "hasErrorInRow(2), #3"); + question.visibleRows[0].cellClick(question.columns[0]); + assert.deepEqual(question.value, { row1: "col1" }, "value is set #4"); + assert.equal(question.hasErrorInRow(question.visibleRows[0]), false, "hasErrorInRow(0), #5"); + assert.equal(question.hasErrorInRow(question.visibleRows[1]), false, "hasErrorInRow(1), #6"); + assert.equal(question.hasErrorInRow(question.visibleRows[2]), false, "hasErrorInRow(2), #7"); +}); QUnit.test("check row randomization in design mode", (assert) => { var json = {