diff --git a/packages/survey-creator-core/src/creator-base.ts b/packages/survey-creator-core/src/creator-base.ts index b704f1b7cf..0919e2fd9b 100644 --- a/packages/survey-creator-core/src/creator-base.ts +++ b/packages/survey-creator-core/src/creator-base.ts @@ -2188,7 +2188,8 @@ export class SurveyCreatorModel extends Base survey: survey, reason: reason, area: area, - model: !!model ? model : this.currentPlugin?.model + model: !!model ? model : this.currentPlugin?.model, + obj: area === "property-grid" && model ? model.obj : undefined }); if (reason === "designer") { this.onDesignerSurveyCreated.fire(this, { survey: survey }); diff --git a/packages/survey-creator-core/src/creator-events-api.ts b/packages/survey-creator-core/src/creator-events-api.ts index e8eb205827..35c3db7156 100644 --- a/packages/survey-creator-core/src/creator-events-api.ts +++ b/packages/survey-creator-core/src/creator-events-api.ts @@ -608,6 +608,10 @@ export interface SurveyInstanceCreatedEvent { * A survey that represents the Survey Creator UI element to be displayed. Use the [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model) API to modify the survey. */ survey: SurveyModel; + /** + * A survey element being edited in the Property Grid. Present only if the `options.area` parameter equals `"property-grid"`. + */ + obj?: Base; /** * Obsolete. Use `options.area` instead. */ diff --git a/packages/survey-creator-core/tests/creator-base.tests.ts b/packages/survey-creator-core/tests/creator-base.tests.ts index 2b9c18e9b3..bd4409955b 100644 --- a/packages/survey-creator-core/tests/creator-base.tests.ts +++ b/packages/survey-creator-core/tests/creator-base.tests.ts @@ -4548,3 +4548,26 @@ test("onSetPropertyEditorOptions -> onConfigureTablePropertyEditor", (): any => creator.onSetPropertyEditorOptionsCallback("choices", question, callBackOptions); expect(callBackOptions.allowBatchEdit).toBeFalsy(); }); +test("creator.onSurveyInstanceCreated from property Grid", () => { + const creator = new CreatorTester(); + const selectedTypes = new Array(); + creator.onSurveyInstanceCreated.add((sender, options) => { + if (options.area === "property-grid") { + if(options.obj) { + selectedTypes.push(options.obj.getType()); + } + } + }); + creator.JSON = { + elements: [ + { name: "q1", type: "text" }, + { + name: "q2", + type: "radiogroup" + } + ] + }; + creator.selectQuestionByName("q1"); + creator.selectQuestionByName("q2"); + expect(selectedTypes).toStrictEqual(["survey", "text", "radiogroup"]); +});