diff --git a/src/editor.ts b/src/editor.ts index a6b3f8a692..2f9df5d111 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -3156,6 +3156,12 @@ export class SurveyCreator implements ISurveyObjectEditorOptions { list: list, }; this.onConditionQuestionsGetList.fire(this, options); + if (options.list !== list) { + list.splice(0, list.length); + for (var i = 0; i < options.list.length; i++) { + list.push(options.list[i]); + } + } } startUndoRedoTransaction() { this.undoRedoManager.startTransaction("Edit Element in Modal Window"); @@ -3355,4 +3361,3 @@ function addEmptyPanelElement( root.appendChild(eDiv); return eDiv; } - diff --git a/tests/surveyCreatorTests.ts b/tests/surveyCreatorTests.ts index 34619adfd1..e8790758da 100644 --- a/tests/surveyCreatorTests.ts +++ b/tests/surveyCreatorTests.ts @@ -4,9 +4,9 @@ import { SurveyCreator } from "../src/editor"; import { PagesEditorViewModel } from "../src/components/pages-editor"; import { SurveyQuestionEditor } from "../src/questionEditors/questionEditor"; import { SurveyObjectProperty } from "../src/objectProperty"; -import { QuestionToolbox } from "../src/components/toolbox"; import { AccordionViewModel } from "../src/utils/accordion"; import { isPropertyVisible } from "../src/utils/utils"; +import { SurveyPropertyConditionEditor } from "../src/propertyEditors/propertyConditionEditor"; export default QUnit.module("surveyEditorTests"); @@ -1599,3 +1599,30 @@ QUnit.test("generate element name based on another survey", function (assert) { "Generate question10 name, next after question10" ); }); +QUnit.test("creator.onConditionQuestionsGetList, Bug#957", function (assert) { + var creator = new SurveyCreator(); + creator.onConditionQuestionsGetList.add(function (sender, options) { + options.list = options.list.filter( + (question) => question.getType() === "text" + ); + }); + creator.JSON = { + elements: [ + { name: "q1", type: "text" }, + { name: "q2", type: "text" }, + { name: "q3", type: "dropdown" }, + { name: "q4", type: "checkbox" }, + { name: "q5", type: "radiogroup" }, + ], + }; + var question = creator.survey.getQuestionByName("q1"); + var property = Survey.Serializer.findProperty("question", "visibleIf"); + var editor = new SurveyPropertyConditionEditor(property); + editor.options = creator; + editor.object = question; + editor.beforeShow(); + editor.isEditorShowing = true; + var editorItem = editor.koEditorItems()[0]; + assert.ok(editorItem, "Editor item is created"); + assert.equal(editorItem.nameQuestion.choices.length, 1, "One text question"); +});