Skip to content

Commit

Permalink
Only one duplication error into one matrix cell can be added
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Oct 7, 2023
1 parent 9a36f6e commit a252c0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,10 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
return false;
}
private addDuplicationError(question: Question) {
question.addError(new KeyDuplicationError(this.keyDuplicationError, this));
const keyError = question.errors.find(error => error.getErrorType() === "keyduplicationerror");
if(!keyError) {
question.addError(new KeyDuplicationError(this.keyDuplicationError, this));
}
}
public getFirstQuestionToFocus(withError: boolean): Question {
return this.getFirstCellQuestion(withError);
Expand Down
20 changes: 20 additions & 0 deletions tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,23 @@ QUnit.test("question.onHidingContent", function (assert) {
assert.equal(counter1, 1, "cell on complete");
assert.equal(counter2, 2, "detail questions");
});
QUnit.test("checkIfValueInRowDuplicated has only one duplicated error", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "matrixdynamic",
name: "matrix",
columns: [{ name: "col1", isUnique: true }]
},
],
});
const matrix = <QuestionMatrixDropdownModelBase>survey.getQuestionByName("matrix");
matrix.value = [{ col1: "a" }, { col1: "a" }];
const row = matrix.visibleRows[0];
const q = row.getQuestionByColumnName("col1");
matrix.checkIfValueInRowDuplicated(row, q);
matrix.checkIfValueInRowDuplicated(row, q);
matrix.checkIfValueInRowDuplicated(row, q);
assert.equal(q.errors.length, 1, "One error only");
assert.equal(q.errors[0].getErrorType(), "keyduplicationerror", "Correct error is added");
});

0 comments on commit a252c0e

Please sign in to comment.