Skip to content

Commit eb43fbd

Browse files
committed
Fix: Changing of options.list from onConditionQuestionsGetList is ignored for T5191
#957
1 parent 37116d3 commit eb43fbd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/editor.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,12 @@ export class SurveyCreator implements ISurveyObjectEditorOptions {
31563156
list: list,
31573157
};
31583158
this.onConditionQuestionsGetList.fire(this, options);
3159+
if (options.list !== list) {
3160+
list.splice(0, list.length);
3161+
for (var i = 0; i < options.list.length; i++) {
3162+
list.push(options.list[i]);
3163+
}
3164+
}
31593165
}
31603166
startUndoRedoTransaction() {
31613167
this.undoRedoManager.startTransaction("Edit Element in Modal Window");
@@ -3355,4 +3361,3 @@ function addEmptyPanelElement(
33553361
root.appendChild(eDiv);
33563362
return eDiv;
33573363
}
3358-

tests/surveyCreatorTests.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { SurveyCreator } from "../src/editor";
44
import { PagesEditorViewModel } from "../src/components/pages-editor";
55
import { SurveyQuestionEditor } from "../src/questionEditors/questionEditor";
66
import { SurveyObjectProperty } from "../src/objectProperty";
7-
import { QuestionToolbox } from "../src/components/toolbox";
87
import { AccordionViewModel } from "../src/utils/accordion";
98
import { isPropertyVisible } from "../src/utils/utils";
9+
import { SurveyPropertyConditionEditor } from "../src/propertyEditors/propertyConditionEditor";
1010

1111
export default QUnit.module("surveyEditorTests");
1212

@@ -1599,3 +1599,30 @@ QUnit.test("generate element name based on another survey", function (assert) {
15991599
"Generate question10 name, next after question10"
16001600
);
16011601
});
1602+
QUnit.test("creator.onConditionQuestionsGetList, Bug#957", function (assert) {
1603+
var creator = new SurveyCreator();
1604+
creator.onConditionQuestionsGetList.add(function (sender, options) {
1605+
options.list = options.list.filter(
1606+
(question) => question.getType() === "text"
1607+
);
1608+
});
1609+
creator.JSON = {
1610+
elements: [
1611+
{ name: "q1", type: "text" },
1612+
{ name: "q2", type: "text" },
1613+
{ name: "q3", type: "dropdown" },
1614+
{ name: "q4", type: "checkbox" },
1615+
{ name: "q5", type: "radiogroup" },
1616+
],
1617+
};
1618+
var question = creator.survey.getQuestionByName("q1");
1619+
var property = Survey.Serializer.findProperty("question", "visibleIf");
1620+
var editor = new SurveyPropertyConditionEditor(property);
1621+
editor.options = creator;
1622+
editor.object = question;
1623+
editor.beforeShow();
1624+
editor.isEditorShowing = true;
1625+
var editorItem = editor.koEditorItems()[0];
1626+
assert.ok(editorItem, "Editor item is created");
1627+
assert.equal(editorItem.nameQuestion.choices.length, 1, "One text question");
1628+
});

0 commit comments

Comments
 (0)