Skip to content

Commit

Permalink
Matrix dynamic with editing object doesn't work correctly on adding a…
Browse files Browse the repository at this point in the history
… new item in collection fix #7328
  • Loading branch information
andrewtelnov committed Nov 10, 2023
1 parent 0f3f5c6 commit 94123cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
const lastDelRow = this.lastDeletedRow;
this.lastDeletedRow = undefined;
const rows = this.generatedVisibleRows;
if(!Array.isArray(val) || Math.abs(rows.length - val.length) > 1) return false;
if(!Array.isArray(val) || Math.abs(rows.length - val.length) > 1 || rows.length === val.length) return false;
const index = this.getInsertedDeletedIndex(rows, val);
if(rows.length > val.length) {
this.lastDeletedRow = rows[index];
Expand Down
29 changes: 29 additions & 0 deletions tests/editingObjectTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { QuestionMultipleTextModel } from "../src/question_multipletext";
import { QuestionMatrixModel } from "../src/question_matrix";
import { Question } from "../src/question";
import { QuestionCheckboxModel } from "../src/question_checkbox";
import { SurveyTriggerComplete } from "../src/trigger";

export default QUnit.module("Survey.editingObj Tests");

Expand Down Expand Up @@ -1472,3 +1473,31 @@ QUnit.test("Allow to set empty string into localization string & string property
assert.strictEqual(q2.placeholder, "", "q2.placeholder value is empty");
assert.strictEqual(q2.minWidth, "", "q2.minWidth value is empty");
});
QUnit.test("Edit triggers array", function (assert) {
const survey = new SurveyModel();

const editSurvey = new SurveyModel({
elements: [
{
type: "matrixdynamic",
name: "triggers",
columns: [{ cellType: "text", name: "type" }],
rowCount: 0,
},
],
});
editSurvey.onMatrixCellCreated.add((sender, options) => {
const obj = options.row.editingObj;
if(obj) {
options.cell.value = obj.getType();
}
});
const matrix = <QuestionMatrixDynamicModel>(
editSurvey.getQuestionByName("triggers")
);
editSurvey.editingObj = survey;
assert.equal(matrix.visibleRows.length, 0, "There is no triggers");
survey.triggers.push(new SurveyTriggerComplete());
assert.equal(matrix.visibleRows.length, 1, "There is one trigger");
assert.equal(matrix.visibleRows[0].cells[0].value, "completetrigger", "correct trigger type");
});

0 comments on commit 94123cc

Please sign in to comment.