Skip to content

Commit

Permalink
creator.onSurveyInstanceCreated - No property which returns a form el… (
Browse files Browse the repository at this point in the history
#5811)

* creator.onSurveyInstanceCreated - No property which returns a form element for options.area: "property-grid" fix #5808

* Describe the `obj` property in the `SurveyInstanceCreatedEvent` interface

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
andrewtelnov and RomanTsukanov authored Aug 22, 2024
1 parent 3fbd04b commit f7a716e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
4 changes: 4 additions & 0 deletions packages/survey-creator-core/src/creator-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
23 changes: 23 additions & 0 deletions packages/survey-creator-core/tests/creator-base.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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"]);
});

0 comments on commit f7a716e

Please sign in to comment.