Skip to content

Commit 6e589ab

Browse files
authored
Dynamic Matrix - A column doesn't render a unique value error on each row when a column has an Expression validator fix #11155 (#11156)
* Dynamic Matrix - A column doesn't render a unique value error on each row when a column has an Expression validator fix #11155 * Add validation check for unique column values on value change in MatrixDropdownRowModelBase * Update test case for isUnique error in second matrix to reference bug #11155
1 parent 18c5410 commit 6e589ab

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

packages/survey-core/src/question_matrixdropdownbase.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ export class MatrixDropdownRowModelBase extends DynamicItemModelBase implements
544544
this.runTriggersOnSetValue(changedName, newColumnValue);
545545
}
546546
this.onAnyValueChanged(rowName, "");
547+
if (!isComment && changedQuestion) {
548+
const survey = <any>this.getSurvey();
549+
if (survey && survey.isValidateOnValueChanged) {
550+
const col = this.data.columns.filter(c => c.name === name)[0];
551+
if (col && col.isUnique) {
552+
this.data.checkIfValueInRowDuplicated(this, changedQuestion);
553+
}
554+
}
555+
}
547556
}
548557

549558
private onCellValueChanging(question: Question, newValue: any, isComment: boolean): any {

packages/survey-core/tests/question_matrixdynamictests.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11529,4 +11529,77 @@ QUnit.test("onMatrixCellValueChanged event should have oldValue and value in opt
1152911529
assert.equal(changedLog.length, 6, "Six changes logged");
1153011530
assert.equal(changedLog[5].value, "text2", "New text value is text2");
1153111531
assert.equal(changedLog[5].oldValue, "text1", "Old text value is text1");
11532+
});
11533+
11534+
QUnit.test("isUnique error should appear in second matrix with validators when duplicate values are set, bug#11155", function (assert) {
11535+
const survey = new SurveyModel({
11536+
pages: [
11537+
{
11538+
name: "page1",
11539+
elements: [
11540+
{
11541+
type: "matrixdynamic",
11542+
name: "matrix1",
11543+
columns: [
11544+
{
11545+
name: "b",
11546+
cellType: "text",
11547+
isUnique: true
11548+
},
11549+
{
11550+
name: "c",
11551+
cellType: "text"
11552+
}
11553+
]
11554+
},
11555+
{
11556+
type: "matrixdynamic",
11557+
name: "matrix2",
11558+
columns: [
11559+
{
11560+
name: "b",
11561+
cellType: "text",
11562+
isUnique: true,
11563+
validators: [
11564+
{
11565+
type: "expression",
11566+
text: "'{row.c} empty'",
11567+
expression: "{row.c} empty"
11568+
}
11569+
]
11570+
},
11571+
{
11572+
name: "c",
11573+
cellType: "text"
11574+
}
11575+
]
11576+
}
11577+
]
11578+
}
11579+
],
11580+
checkErrorsMode: "onValueChanged"
11581+
});
11582+
11583+
const matrix1 = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix1");
11584+
const matrix2 = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix2");
11585+
const rows1 = matrix1.visibleRows;
11586+
const rows2 = matrix2.visibleRows;
11587+
11588+
// Set duplicate values in matrix1
11589+
const cell1_row0 = rows1[0].getQuestionByColumnName("b");
11590+
const cell1_row1 = rows1[1].getQuestionByColumnName("b");
11591+
cell1_row0.value = "abc";
11592+
cell1_row1.value = "abc";
11593+
11594+
assert.equal(cell1_row0.errors.length, 1, "matrix1 row0 cell 'b' has unique error");
11595+
assert.equal(cell1_row1.errors.length, 1, "matrix1 row1 cell 'b' has unique error");
11596+
11597+
// Set duplicate values in matrix2
11598+
const cell2_row0 = rows2[0].getQuestionByColumnName("b");
11599+
const cell2_row1 = rows2[1].getQuestionByColumnName("b");
11600+
cell2_row0.value = "abc";
11601+
cell2_row1.value = "abc";
11602+
11603+
assert.equal(cell2_row0.errors.length, 1, "matrix2 row0 cell 'b' has unique error");
11604+
assert.equal(cell2_row1.errors.length, 1, "matrix2 row1 cell 'b' should have unique error");
1153211605
});

0 commit comments

Comments
 (0)