Skip to content

Commit

Permalink
Merge branch 'master' into bug/C4484-memory-leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv2013 committed Aug 30, 2023
2 parents 6ad2314 + 759a0bd commit ef65375
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export interface ISurveyElement extends IShortcutText {
getType(): string;
setVisibleIndex(value: number): number;
locStrsChanged(): any;
delete(): any;
delete(doDispose?: boolean): void;
toggleState(): void;
stateChangedCallback(): void;
getTitleToolbar(): AdaptiveActionContainer;
Expand Down
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class Base {
if (this.isPropertyEmpty(res)) {
const locStr = this.localizableStrings ? this.localizableStrings[name] : undefined;
if(locStr) return locStr.text;
if (defaultValue != null) return defaultValue;
if (defaultValue !== null && defaultValue !== undefined) return defaultValue;
const propDefaultValue = this.getDefaultPropertyValue(name);
if(propDefaultValue !== undefined) return propDefaultValue;
}
Expand Down
3 changes: 2 additions & 1 deletion src/choicesRestful.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ export class ChoicesRestful extends Base {
*/

public get path(): string {
return this.getPropertyValue("path", "");
const res = this.getPropertyValue("path");
return !!res ? res : "";
}
public set path(val: string) {
this.setPropertyValue("path", val);
Expand Down
2 changes: 1 addition & 1 deletion src/dropdownListModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class DropdownListModel extends Base {
}

public onClick(event: any): void {
if(this.question.readOnly) return;
if (this.question.readOnly || this.question.isDesignMode) return;
this._popupModel.toggleVisibility();
this.focusItemOnClickAndPopup();
if (this.searchEnabled && !!event && !!event.target) {
Expand Down
6 changes: 4 additions & 2 deletions src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ export class PanelModelBase extends SurveyElement<Question>
(this.showTitle && this.isDesignMode && settings.designMode.showEmptyTitles)
);
}
public delete(): void {
public delete(doDispose: boolean = true): void {
this.removeFromParent();
this.dispose();
if(doDispose) {
this.dispose();
}
}
protected removeFromParent(): void {}
protected canShowTitle(): boolean { return true; }
Expand Down
13 changes: 10 additions & 3 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,13 @@ export class Question extends SurveyElement<Question>
public getPanel(): IPanel {
return null;
}
public delete(): void {
public delete(doDispose: boolean = true): void {
this.removeFromParent();
this.dispose();
if(doDispose) {
this.dispose();
} else {
this.resetDependedQuestions();
}
}
protected removeFromParent(): void {
if (!!this.parent) {
Expand Down Expand Up @@ -2324,10 +2328,13 @@ export class Question extends SurveyElement<Question>
}
public dispose(): void {
super.dispose();
this.resetDependedQuestions();
this.destroyResizeObserver();
}
private resetDependedQuestions(): void {
for (var i = 0; i < this.dependedQuestions.length; i++) {
this.dependedQuestions[i].resetDependedQuestion();
}
this.destroyResizeObserver();
}
}
function makeNameValid(str: string): string {
Expand Down
5 changes: 2 additions & 3 deletions src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class QuestionBooleanModel extends Question {
return this.value == this.getValueTrue();
}
public set booleanValue(val: any) {
if (this.isReadOnly) {
if (this.isReadOnly || this.isDesignMode) {
return;
}
this.setBooleanValue(val);
Expand Down Expand Up @@ -258,9 +258,8 @@ export class QuestionBooleanModel extends Question {
}
public onKeyDownCore(event: any): boolean {
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
preventDefaults(event);
event.stopPropagation();
this.calculateBooleanValueByEvent(event, event.key === "ArrowRight");
return;
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
public get isQuestion() {
return false;
}
public delete() { }
public delete(doDispose: boolean): void { }
//ILocalizableOwner
locOwner: ILocalizableOwner;
/**
Expand Down
18 changes: 18 additions & 0 deletions tests/dropdown_list_model_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,21 @@ QUnit.test("lazy loading clear value", function (assert) {
assert.equal(dropdownListModel.inputStringRendered, "");
});

QUnit.test("Dropdown should noy be open on click in design mode", (assert) => {
const survey = new SurveyModel(jsonDropdown);
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
const dropdownListModel = question.dropdownListModel;
assert.ok(dropdownListModel.popupModel);

const list: ListModel = dropdownListModel.popupModel.contentComponentData.model as ListModel;
assert.equal(list.actions.length, 28);
assert.notOk(dropdownListModel.popupModel.isVisible);
dropdownListModel.onClick(new Event("click"));
assert.ok(dropdownListModel.popupModel.isVisible);
dropdownListModel.onClick(new Event("click"));
assert.notOk(dropdownListModel.popupModel.isVisible);
survey.setDesignMode(true);

dropdownListModel.onClick(new Event("click"));
assert.notOk(dropdownListModel.popupModel.isVisible);
});
46 changes: 46 additions & 0 deletions tests/questionBooleanTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,50 @@ QUnit.test("Check boolean labelRenderedAriaID", function (assert) {

question.titleLocation = "hidden";
assert.strictEqual(question.labelRenderedAriaID.indexOf("_ariaTitle") !== -1, true);
});

QUnit.test("Boolean shouldn't call preventDefault on key down", function (assert) {
var json = {
"elements": [
{
"type": "boolean",
"name": "bool",
}
]
};
var survey = new SurveyModel(json);
var question = <QuestionBooleanModel>survey.getAllQuestions()[0];

let pdCount = 0;
let spCount = 0;
const event = {
key: "ArrowLeft",
target: document.createElement("div"),
preventDefault: () => { pdCount++; },
stopPropagation: () => { spCount++; }
};
question.onKeyDownCore(event);
assert.equal(pdCount, 0);
assert.equal(spCount, 1);
});
QUnit.test("Boolean shouldn't set booleanValue in design time", function (assert) {
var json = {
"elements": [
{
"type": "boolean",
"name": "bool",
}
]
};
var survey = new SurveyModel(json);
var question = <QuestionBooleanModel>survey.getAllQuestions()[0];

assert.equal(question.value, undefined);

question.booleanValue = true;
assert.equal(question.value, true);

survey.setDesignMode(true);
question.booleanValue = false;
assert.equal(question.value, true);
});
22 changes: 22 additions & 0 deletions tests/question_baseselecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,21 @@ QUnit.test("Check isUsingCarryForward on deleting matrix dynamic question", func
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Check isUsingCarryForward on deleting matrix dynamic question with doDispose = false parameter", function (assert) {
const survey = new SurveyModel();
survey.setDesignMode(true);
survey.fromJSON({ elements: [
{ type: "matrixdynamic", name: "q1" },
{ type: "dropdown", name: "q2", choicesFromQuestion: "q1" }
] });
const q1 = <QuestionSelectBase>survey.getQuestionByName("q1");
const q2 = <QuestionSelectBase>survey.getQuestionByName("q2");
assert.equal(q2.choicesFromQuestion, "q1", "set correctly");
assert.equal(q2.isUsingCarryForward, true, "Carryforward flag is set");
q1.delete(false);
assert.notOk(q2.choicesFromQuestion, "it is empty");
assert.equal(q2.isUsingCarryForward, false, "Carryforward flag is unset");
});
QUnit.test("Use carryForward with panel dynamic + update data on survey.data=data;", function (assert) {
const survey = new SurveyModel({ elements: [
{ type: "checkbox", name: "q2", choicesFromQuestion: "q1", choiceValuesFromQuestion: "q1-q2", choiceTextsFromQuestion: "q1-q3" },
Expand All @@ -1189,4 +1204,11 @@ QUnit.test("Use carryForward with panel dynamic + update data on survey.data=dat
assert.equal(q2.visibleChoices[1].value, 2, "the second value is correct");
assert.equal(q2.visibleChoices[1].text, "Item 2", "the second text is correct");
});
QUnit.test("Allow to override default value fro choicesByUrl.path Bug#6766", function (assert) {
const prop = Serializer.findProperty("choicesByUrl", "path");
prop.defaultValue = "list";
const q1 = new QuestionDropdownModel("q1");
assert.equal(q1.choicesByUrl.path, "list", "get new default value for path");
prop.defaultValue = undefined;
});

0 comments on commit ef65375

Please sign in to comment.