Skip to content

Commit

Permalink
The options.reason parameter within the onQuestionAdded event returns…
Browse files Browse the repository at this point in the history
… undefined when a question is dropped from a Toolbox fixed surveyjs#4381 (surveyjs#4387)
  • Loading branch information
andrewtelnov authored Jul 28, 2023
1 parent e1f55b7 commit be779dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export class ToolboxToolViewModel extends Base {
this._node = pointerDownEvent.currentTarget;
this._node.classList.add("svc-toolbox__tool--pressed");
document.addEventListener("pointerup", this.onPointerUp);
this.creator.onDragDropItemStart();
}

private _node: any
private onPointerUp = (pointerUpEvent) => {
this.creator.onDragDropItemEnd();
this._node.classList.remove("svc-toolbox__tool--pressed");
this._node = null;
document.removeEventListener("pointerup", this.onPointerUp);
Expand Down
6 changes: 6 additions & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,12 @@ export class CreatorBase extends Base
}

private addNewElementReason: string;
public onDragDropItemStart(): void {
this.addNewElementReason = "DROPPED_FROM_TOOLBOX";
}
public onDragDropItemEnd(): void {
this.addNewElementReason = undefined;
}
@ignoreUndoRedo()
private doOnQuestionAdded(question: Question, parentPanel: any) {
question.name = this.generateUniqueName(question, question.name);
Expand Down
12 changes: 11 additions & 1 deletion packages/survey-creator-core/tests/creator-base.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { TabJsonEditorTextareaPlugin } from "../src/components/tabs/json-editor-
import { TabJsonEditorAcePlugin } from "../src/components/tabs/json-editor-ace";
import { isTextInput } from "../src/creator-base";
import { ItemValueWrapperViewModel } from "../src/components/item-value";
import { getNextItemText } from "../src/utils/utils";
import { ToolboxToolViewModel } from "../src/components/toolbox/toolbox-tool";

import {
getElementWrapperComponentData,
Expand Down Expand Up @@ -3741,6 +3741,16 @@ test("Reason of question Added from toolbox, onclicking add question button, on
expect(reason[3]).toEqual("ELEMENT_COPIED");
expect(reason[4]).toEqual("ELEMENT_COPIED");
expect(reason[5]).toEqual("ELEMENT_COPIED");

const toolboxViwer = new ToolboxToolViewModel(creator.toolbox.items[0], creator);
toolboxViwer.click({});
expect(reason).toHaveLength(7);
expect(reason[6]).toEqual("ADDED_FROM_TOOLBOX");
creator.onDragDropItemStart();
creator.survey.pages[0].addNewQuestion("text", "qqq1");
creator.onDragDropItemEnd();
expect(reason).toHaveLength(8);
expect(reason[7]).toEqual("DROPPED_FROM_TOOLBOX");
});
test("Initial Property Grid category expanded state", (): any => {
const creator = new CreatorTester();
Expand Down

0 comments on commit be779dc

Please sign in to comment.