Skip to content

Commit

Permalink
The Undo operation doesn't work for matrix dropdown column "choices" …
Browse files Browse the repository at this point in the history
…property fix #8791 (#8792)
  • Loading branch information
andrewtelnov authored Sep 9, 2024
1 parent c666332 commit 766c65d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
17 changes: 4 additions & 13 deletions packages/survey-core/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,27 +630,18 @@ export class Base {
propertyName: item.ownerPropertyName,
});
}
protected onPropertyValueChanged(
name: string,
oldValue: any,
newValue: any
) { }
protected propertyValueChanged(
name: string,
oldValue: any,
newValue: any,
arrayChanges?: ArrayChanges,
target?: Base
) {
protected onPropertyValueChanged(name: string, oldValue: any, newValue: any): void { }
protected propertyValueChanged(name: string, oldValue: any, newValue: any, arrayChanges?: ArrayChanges, target?: Base): void {
if (this.isLoadingFromJson) return;
this.updateBindings(name, newValue);
this.onPropertyValueChanged(name, oldValue, newValue);
this.onPropertyChanged.fire(this, {
name: name,
oldValue: oldValue,
newValue: newValue,
arrayChanges: arrayChanges,
target: target
});

this.doPropertyValueChangedCallback(
name,
oldValue,
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/header.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Base } from "./base";
import { Base, ArrayChanges } from "./base";
import { HorizontalAlignment, VerticalAlignment } from "./base-interfaces";
import { Serializer, property } from "./jsonobject";
import { SurveyModel } from "./survey";
Expand Down Expand Up @@ -192,7 +192,7 @@ export class Cover extends Base {
backgroundSize: this.calcBackgroundSize(this.backgroundImageFit),
};
}
protected propertyValueChanged(name: string, oldValue: any, newValue: any): void {
protected propertyValueChanged(name: string, oldValue: any, newValue: any, arrayChanges?: ArrayChanges, target?: Base): void {
super.propertyValueChanged(name, oldValue, newValue);
if (name === "backgroundColor" || name === "backgroundImage" || name === "overlapEnabled") {
this.updateHeaderClasses();
Expand Down
10 changes: 6 additions & 4 deletions packages/survey-core/src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonObject, JsonObjectProperty, Serializer } from "./jsonobject";
import { Question } from "./question";
import { Base } from "./base";
import { Base, ArrayChanges } from "./base";
import { ISurvey, IWrapperObject } from "./base-interfaces";
import { ItemValue } from "./itemvalue";
import { QuestionSelectBase } from "./question_baseselect";
Expand Down Expand Up @@ -728,7 +728,9 @@ export class MatrixDropdownColumn extends Base
this.propertyValueChanged(
options.name,
options.oldValue,
options.newValue
options.newValue,
options.arrayChanges,
options.target
);
});
this.templateQuestion.onItemValuePropertyChanged.add((sender, options) => {
Expand Down Expand Up @@ -807,8 +809,8 @@ export class MatrixDropdownColumn extends Base
};
}
}
protected propertyValueChanged(name: string, oldValue: any, newValue: any) {
super.propertyValueChanged(name, oldValue, newValue);
protected propertyValueChanged(name: string, oldValue: any, newValue: any, arrayChanges?: ArrayChanges, target?: Base): void {
super.propertyValueChanged(name, oldValue, newValue, arrayChanges, target);
if (name === "isRequired") {
this.updateIsRenderedRequired(newValue);
}
Expand Down
43 changes: 42 additions & 1 deletion packages/survey-core/tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonObjectProperty, Serializer } from "../src/jsonobject";
import { Serializer } from "../src/jsonobject";
import { QuestionDropdownModel } from "../src/question_dropdown";
import { QuestionMatrixDropdownModelBase } from "../src/question_matrixdropdownbase";
import { MatrixDropdownColumn } from "../src/question_matrixdropdowncolumn";
Expand Down Expand Up @@ -1662,4 +1662,45 @@ QUnit.test("showInMultipleColumns - add choice item", function (assert) {
assert.equal(rows[0].cells[1].question.visibleChoices[3].value, "col4", "row1 question 3");
assert.equal(rows[1].cells[1].question.visibleChoices[0].value, "col1", "row2 question 1");
assert.equal(rows[1].cells[1].question.visibleChoices[3].value, "col4", "row2 question 3");
});
QUnit.test("The Undo operation doesn't work for matrix dropdown column 'choices' property, Bug#8791", function (assert) {
const survey = new SurveyModel({
elements: [
{
"type": "matrixdropdown",
"name": "matrix",
"columns": [
{
"name": "column1",
"cellType": "checkbox",
"choices": ["col1", "col2", "col3"],
}
]
}
]
});
const matrix = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
let propName;
let arrayChangesTest;
let counter = 0;
let senderName;
survey.onPropertyValueChangedCallback = (
name: string,
oldValue: any,
newValue: any,
sender: any,
arrayChanges: any
) => {
if(name === "choices") {
counter ++;
propName = name;
senderName = sender.name;
arrayChangesTest = arrayChanges;
}
};
matrix.columns[0].choices.push(new ItemValue("col4"));
assert.equal(counter, 1, "counter");
assert.equal(propName, "choices", "propName");
assert.equal(senderName, "column1", "senderName");
assert.ok(arrayChangesTest, "arrayChanges");
});

0 comments on commit 766c65d

Please sign in to comment.