Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix dynamic with editing object doesn't work correctly on adding a… #7329

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});