Skip to content

Commit

Permalink
Dynamic Matrix - The column's choices inplace editor doesn't remove t…
Browse files Browse the repository at this point in the history
…he None item fix #5041 (#5042)
  • Loading branch information
andrewtelnov authored Jan 2, 2024
1 parent 57cddea commit 3261b26
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/survey-creator-core/src/components/matrix-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
43 changes: 42 additions & 1 deletion packages/survey-creator-core/tests/question-editors.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionMatrixDropdownModel>creator.survey.getQuestionByName("q1");
let question = matrix.visibleRows[0].cells[0].question;
let editSurvey = new MatrixCellWrapperEditSurvey(creator, question, matrix.columns[0]);
let editQuestion = <QuestionCheckboxModel>editSurvey.question;
expect(editQuestion.getType()).toEqual("checkbox");
editQuestion.showSelectAllItem = true;
editQuestion.showNoneItem = true;
editQuestion.showOtherItem = true;
editSurvey.apply();
const columnQuestion = <QuestionCheckboxModel>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 = <QuestionCheckboxModel>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;
Expand Down

0 comments on commit 3261b26

Please sign in to comment.