From 3261b26e2ce78875b38bfae8a1a8ba6320977d9d Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 2 Jan 2024 12:57:21 +0200 Subject: [PATCH] Dynamic Matrix - The column's choices inplace editor doesn't remove the None item fix #5041 (#5042) --- .../src/components/matrix-cell.ts | 5 +++ .../tests/question-editors.tests.ts | 43 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/survey-creator-core/src/components/matrix-cell.ts b/packages/survey-creator-core/src/components/matrix-cell.ts index 6576a5b68d..c74aed802e 100644 --- a/packages/survey-creator-core/src/components/matrix-cell.ts +++ b/packages/survey-creator-core/src/components/matrix-cell.ts @@ -45,6 +45,11 @@ export class MatrixCellWrapperEditSurvey { questionJSON.cellType = prevCellType; } if(Helpers.isTwoValueEquals(questionJSON, columnJSON)) return; + for(let key in columnJSON) { + if(questionJSON[key] === undefined && (columnJSON[key] === true || columnJSON[key] === false)) { + questionJSON[key] = !columnJSON[key]; + } + } column.fromJSON(questionJSON); matrix.onColumnCellTypeChanged(column); this.creator.setModified({ type: "MATRIX_CELL_EDITOR", column: column }); diff --git a/packages/survey-creator-core/tests/question-editors.tests.ts b/packages/survey-creator-core/tests/question-editors.tests.ts index 0f8cdda763..22b4e2d359 100644 --- a/packages/survey-creator-core/tests/question-editors.tests.ts +++ b/packages/survey-creator-core/tests/question-editors.tests.ts @@ -200,11 +200,52 @@ test("Edit matrix cell question", (): any => { expect(columnName).toBe("column1"); question = matrix.visibleRows[0].cells[0].question; - editSurvey = new MatrixCellWrapperEditSurvey(creator, question); + editSurvey = new MatrixCellWrapperEditSurvey(creator, question, editQuestion.choices[0]); editSurvey.apply(); expect(modifiedCounter).toBe(1); expect(stateCounter).toBe(1); }); +test("Edit matrix cell question & selectAll, other and none", (): any => { + let creator = new CreatorTester(); + creator.JSON = { + "elements": [ + { + "type": "matrixdropdown", + "name": "q1", + "columns": [{ name: "column1", cellType: "checkbox" }], + "choices": ["item1", "item2"], + "rows": ["row1", "row2"] + } + ] + }; + const matrix = creator.survey.getQuestionByName("q1"); + let question = matrix.visibleRows[0].cells[0].question; + let editSurvey = new MatrixCellWrapperEditSurvey(creator, question, matrix.columns[0]); + let editQuestion = editSurvey.question; + expect(editQuestion.getType()).toEqual("checkbox"); + editQuestion.showSelectAllItem = true; + editQuestion.showNoneItem = true; + editQuestion.showOtherItem = true; + editSurvey.apply(); + const columnQuestion = matrix.columns[0].templateQuestion; + expect(columnQuestion.showSelectAllItem).toBeTruthy(); + expect(columnQuestion.showNoneItem).toBeTruthy(); + expect(columnQuestion.showOtherItem).toBeTruthy(); + + question = matrix.visibleRows[0].cells[0].question; + editSurvey = new MatrixCellWrapperEditSurvey(creator, question, matrix.columns[0]); + editQuestion = editSurvey.question; + expect(editQuestion.showSelectAllItem).toBeTruthy(); + expect(editQuestion.showNoneItem).toBeTruthy(); + expect(editQuestion.showOtherItem).toBeTruthy(); + editQuestion.showSelectAllItem = false; + editQuestion.showNoneItem = false; + editQuestion.showOtherItem = false; + editSurvey.apply(); + expect(columnQuestion.showSelectAllItem).toBeFalsy(); + expect(columnQuestion.showNoneItem).toBeFalsy(); + expect(columnQuestion.showOtherItem).toBeFalsy(); +}); test("QuestionRatingAdornerViewModel add rateValues and call onItemValueAdded event", () => { const creator = new CreatorTester(); let valueFromCallback;