Skip to content

Commit

Permalink
#6501 creator.onQuestionAdded - The creator.text contains a differe…
Browse files Browse the repository at this point in the history
…nt layout depending on whether a question was added by being dragged from a toolbox or added by clicking a toolbox item (#6508)

Fixes #6501
  • Loading branch information
novikov82 authored Feb 4, 2025
1 parent 3a91ce4 commit ab35aaa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,9 @@ export class SurveyCreatorModel extends Base
page = this.addNewPageIntoSurvey();
} else {
this.survey.addPage(page);
page.questions.forEach(question => {
this.doOnQuestionAdded(question, page);
});
}
if (changeSelection) {
this.selectElement(page);
Expand Down Expand Up @@ -2320,6 +2323,7 @@ export class SurveyCreatorModel extends Base
private doOnQuestionAdded(question: Question, parentPanel: any) {
question.name = this.generateUniqueName(question, question.name);
var page = this.getPageByElement(question);
if (!page) return;
var options = { question: question, page: page, reason: this.addNewElementReason };
this.addNewElementReason = undefined;
this.onQuestionAdded.fire(this, options);
Expand Down
26 changes: 25 additions & 1 deletion packages/survey-creator-core/tests/creator-empty.tests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { SurveyModel, settings as surveySettings, Serializer } from "survey-core";
import { SurveyModel, settings as surveySettings, Serializer, QuestionTextModel } from "survey-core";
import { TabDesignerPlugin } from "../src/components/tabs/designer-plugin";
import { settings as creatorSetting, settings } from "../src/creator-settings";
import { CreatorTester } from "./creator-tester";
import { UndoRedoController } from "../src/plugins/undo-redo/undo-redo-controller";
import { TabJsonEditorTextareaPlugin } from "../src/components/tabs/json-editor-textarea";
import { TabTestPlugin } from "../src/components/tabs/test-plugin";
import { TabDesignerViewModel } from "../src/components/tabs/designer";

const multipageJSON = {
pages: [
Expand Down Expand Up @@ -204,3 +205,26 @@ test("Create last question, delete page and select survey in property grid", ():
expect(creator.propertyGrid.editingObj.getType()).toBe("survey");
creatorSetting.defaultNewSurveyJSON = savedNewJSON;
});
test("onQuestionAdded fires correctly when drag drop into new page", () => {
const creator = new CreatorTester();
let json = {};
let cnt = 0;

creator.onQuestionAdded.add((sender, options) => {
cnt++;
json = { ...creator.survey.toJSON() };
});
const newPage = (creator.getPlugin("designer").model as TabDesignerViewModel).newPage;
newPage.addElement(new QuestionTextModel("q1"));
expect(cnt).toBe(1);
expect(json).toStrictEqual({
"pages": [
{
"name": "page1",
"elements": [
{ "name": "q1", "type": "text", },
],
},
],
});
});

0 comments on commit ab35aaa

Please sign in to comment.