Skip to content

Commit

Permalink
Bug/7621 drag onpaneladded (#7622)
Browse files Browse the repository at this point in the history
* The creator.onPanelAdded event is invoked when reordering panels fix #7621

* Fix unit test #7621
  • Loading branch information
andrewtelnov authored Jan 4, 2024
1 parent 957100c commit 67b9244
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/drag-drop-page-helper-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ export class DragDropPageHelperV1 {
elementsToResetSWNL.push(target);
}
}

(this.page.survey as SurveyModel).startMovingQuestion();
if (!!src && !!src.parent) {
(this.page.survey as SurveyModel).startMovingQuestion();
isSamePanel = row.panel == src.parent;
if (isSamePanel) {
row.panel.dragDropMoveElement(src, target, targetIndex);
Expand Down
25 changes: 15 additions & 10 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6550,7 +6550,7 @@ export class SurveyModel extends SurveyElementCore
}
this.updateVisibleIndexes();
this.setCalculatedWidthModeUpdater();
if (!this.isMovingQuestion || this.isDesignMode && !settings.supportCreatorV2) {
if (this.canFireAddElement()) {
this.onQuestionAdded.fire(this, {
question: question,
name: question.name,
Expand All @@ -6562,6 +6562,9 @@ export class SurveyModel extends SurveyElementCore
});
}
}
private canFireAddElement(): boolean {
return !this.isMovingQuestion || this.isDesignMode && !settings.supportCreatorV2;
}
questionRemoved(question: Question) {
this.questionHashesRemoved(
<Question>question,
Expand Down Expand Up @@ -6681,15 +6684,17 @@ export class SurveyModel extends SurveyElementCore
}
this.questionHashesPanelAdded(<PanelModelBase>(<any>panel));
this.updateVisibleIndexes();
this.onPanelAdded.fire(this, {
panel: panel,
name: panel.name,
index: index,
parent: parentPanel,
page: rootPanel,
parentPanel: parentPanel,
rootPanel: rootPanel,
});
if (this.canFireAddElement()) {
this.onPanelAdded.fire(this, {
panel: panel,
name: panel.name,
index: index,
parent: parentPanel,
page: rootPanel,
parentPanel: parentPanel,
rootPanel: rootPanel,
});
}
}
panelRemoved(panel: PanelModel) {
this.updateVisibleIndexes();
Expand Down
59 changes: 49 additions & 10 deletions tests/dragdroptests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,37 +988,76 @@ QUnit.test("Move flow panel up", function (assert) {
});

QUnit.test("Check onQuestionAdded event is not fired", function (assert) {
settings.supportCreatorV2 = false;
var survey = new SurveyModel();
var page = survey.addNewPage("p1");
var question = page.addNewQuestion("question1");
var q1 = page.addNewQuestion("text", "q1");
var q2 = page.addNewQuestion("text", "q2");
var q3 = page.addNewQuestion("text", "q3");
var target = new QuestionTextModel("q1");
var target = new QuestionTextModel("question1");
var eventIsFired = false;
survey.onQuestionAdded
.add(function (sender, options) {
eventIsFired = true;
});
page.dragDropStart(q1, target);
page.dragDropMoveTo(q3, true);
page.dragDropStart(question, target);
page.dragDropMoveTo(q1, true);
page.dragDropFinish();

assert.notOk(eventIsFired, "onQuestionAdded event is not fired while dragging");

survey.setDesignMode(true);
target = new QuestionTextModel("q3");
page.dragDropStart(q3, target);
page.dragDropMoveTo(q1, true);
page.dragDropStart(question, target);
page.dragDropMoveTo(q2, true);
page.dragDropFinish();

assert.notOk(eventIsFired, "onQuestionAdded event is fired while dragging, Creator V1");
assert.ok(eventIsFired, "onQuestionAdded event is fired while dragging, Creator V1");

eventIsFired = false;
settings.supportCreatorV2 = true;
target = new QuestionTextModel("q3");
page.dragDropStart(q1, target);
page.dragDropStart(question, target);
page.dragDropMoveTo(q3, true);
page.dragDropFinish();
settings.supportCreatorV2 = false;

assert.notOk(eventIsFired, "onQuestionAdded event is not fired while dragging, Creator V2");

page.addNewQuestion("text", "q5");
assert.ok(eventIsFired, "onQuestionAdded event is fired on adding new question");
});
QUnit.test("Check onPanelAdded event is not fired", function (assert) {
settings.supportCreatorV2 = false;
var survey = new SurveyModel();
var page = survey.addNewPage("p1");
var panel1 = page.addNewPanel("panel1");
var q1 = page.addNewQuestion("text", "q1");
var q2 = page.addNewQuestion("text", "q2");
var q3 = page.addNewQuestion("text", "q3");
var target = new PanelModel("panel1");
var eventIsFired = false;
survey.onPanelAdded
.add(function (sender, options) {
eventIsFired = true;
});
page.dragDropStart(panel1, target);
page.dragDropMoveTo(q1, true);
page.dragDropFinish();
assert.notOk(eventIsFired, "onPanelAdded event is not fired while dragging");

survey.setDesignMode(true);
page.dragDropStart(panel1, target);
page.dragDropMoveTo(q2, true);
page.dragDropFinish();
assert.ok(eventIsFired, "onPanelAdded event is fired while dragging, Creator V1");

eventIsFired = false;
settings.supportCreatorV2 = true;
page.dragDropStart(panel1, target);
page.dragDropMoveTo(q3, true);
page.dragDropFinish();
assert.notOk(eventIsFired, "onPanelAdded event is not fired while dragging, Creator V2");
settings.supportCreatorV2 = false;

page.addNewPanel("panel2");
assert.ok(eventIsFired, "onPanelAdded event is fired on adding new panel");
});
1 change: 1 addition & 0 deletions tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ QUnit.test("deserialize showOptionsCaption & optionsCaption to placeholder & all
});

QUnit.test("question.showClearButton", assert => {
settings.supportCreatorV2 = false;
const json = {
questions: [
{
Expand Down
1 change: 1 addition & 0 deletions tests/question_tagbox_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ QUnit.test("TagBox readOnlyText property should be reactive, Bug#6830", (assert)
assert.equal(q.dropdownListModel.filterStringPlaceholder, "en-sel", "dropdownlist en, #3");
});
QUnit.test("question.showClearButton", assert => {
settings.supportCreatorV2 = false;
const json = {
questions: [
{
Expand Down

0 comments on commit 67b9244

Please sign in to comment.