Skip to content

Commit 498d66b

Browse files
authored
Validation fails on hidden rows in matrix when specifying eachRowRequired fix #10395 (#10398)
1 parent dad5550 commit 498d66b

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

packages/survey-core/src/question_matrix.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,6 @@ export class QuestionMatrixModel
727727
return !rowsErrors.noValue;
728728
}
729729
private checkErrorsAllRows(modifyErrors: boolean, res: { noValue: boolean, isNotUnique: boolean }, allRowsRequired?: boolean): void {
730-
var rows = this.generatedVisibleRows;
731-
if (!rows) rows = this.visibleRows;
732-
if (!rows) return;
733730
const rowsRequired = this.eachRowRequired || allRowsRequired;
734731
const rowsUnique = this.eachRowUnique;
735732
res.noValue = false;
@@ -738,6 +735,8 @@ export class QuestionMatrixModel
738735
this.errorsInRow = undefined;
739736
}
740737
if (!rowsRequired && !rowsUnique) return;
738+
const rows = this.visibleRows;
739+
if (!rows) return;
741740
const hash: HashTable<any> = {};
742741
for (var i = 0; i < rows.length; i++) {
743742
const val = rows[i].value;

packages/survey-core/tests/question_matrix_tests.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,57 @@ QUnit.test("matrix eachRowRequired & getItemClass", function (assert) {
476476
assert.equal(question.getItemClass(row, column1).indexOf(itemError) > -1, false, "itemError doesn't exist in column 1, #1");
477477
assert.equal(question.getItemClass(row, column2).indexOf(itemError) > -1, false, "itemError doesn't exist in column 2, #1");
478478
});
479+
QUnit.test("matrix eachRowRequired & row visibleIf, Bug#10395.1", function (assert) {
480+
const survey = new SurveyModel({
481+
elements: [
482+
{
483+
type: "matrix",
484+
name: "q1",
485+
columns: ["col1"],
486+
rows: ["row1", { value: "row2", visibleIf: "false" }],
487+
eachRowRequired: true
488+
},
489+
]
490+
});
491+
const question = <QuestionMatrixModel>survey.getQuestionByName("q1");
492+
assert.equal(question.visibleRows.length, 1, "There is one visible row");
493+
question.visibleRows[0].value = "col1";
494+
assert.equal(question.validate(), true, "There is no errors");
495+
});
496+
QUnit.test("matrix eachRowRequired & row visibleIf, Bug#10395.2", function (assert) {
497+
const survey = new SurveyModel({
498+
elements: [
499+
{
500+
type: "matrixdropdown",
501+
name: "q1",
502+
columns: [{ name: "col1", cellType: "text" }],
503+
rows: ["row1", { value: "row2", visibleIf: "false" }],
504+
eachRowRequired: true
505+
},
506+
]
507+
});
508+
const question = <QuestionMatrixModel>survey.getQuestionByName("q1");
509+
assert.equal(question.visibleRows.length, 1, "There is one visible row");
510+
question.visibleRows[0].value = "col1";
511+
assert.equal(question.validate(), true, "There is no errors");
512+
});
513+
QUnit.test("matrix eachRowRequired & row visibleIf, Bug#10395.2", function (assert) {
514+
const survey = new SurveyModel({
515+
elements: [
516+
{
517+
type: "matrixdropdown",
518+
name: "q1",
519+
columns: [{ name: "col1", cellType: "text", isUnique: true }],
520+
rows: ["row1", { value: "row2", visibleIf: "false" }],
521+
eachRowRequired: true
522+
},
523+
]
524+
});
525+
const question = <QuestionMatrixModel>survey.getQuestionByName("q1");
526+
question.value = { row1: "val1", row2: "val1" };
527+
assert.equal(question.visibleRows.length, 1, "There is one visible row");
528+
assert.equal(question.validate(), true, "There is no errors");
529+
});
479530
QUnit.test("hideIfRowsEmpty & question visibleIf, bug#8459", function (assert) {
480531
const survey = new SurveyModel({
481532
elements: [{ type: "matrix", name: "q1", visibleIf: "{a}=1", hideIfRowsEmpty: true, rows: [{ value: "row1", visibleIf: "{b}=2" }] }],

0 commit comments

Comments
 (0)