Skip to content

Commit

Permalink
A question with visible = false is lost on a design surface after dup…
Browse files Browse the repository at this point in the history
…licating a panel fix #6881 (#6882)
  • Loading branch information
andrewtelnov authored Sep 5, 2023
1 parent 8a4f629 commit 7faaec0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,14 @@ export class Question extends SurveyElement<Question>
this.notifySurveyVisibilityChanged();
}
protected onVisibleChanged(): void {
this.setPropertyValue("isVisible", this.isVisible);
this.updateIsVisibleProp();
if (!this.isVisible && this.errors && this.errors.length > 0) {
this.errors = [];
}
}
private updateIsVisibleProp(): void {
this.setPropertyValue("isVisible", this.isVisible);
}
/**
* Specifies whether to use display names for question values in placeholders.
*
Expand Down Expand Up @@ -469,6 +472,9 @@ export class Question extends SurveyElement<Question>
this.runConditions();
}
this.calcRenderedCommentPlaceholder();
if(!this.visible) {
this.updateIsVisibleProp();
}
}
/**
* Returns a survey element (panel or page) that contains the question and allows you to move this question to a different survey element.
Expand Down
29 changes: 29 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17642,4 +17642,33 @@ QUnit.test("SurveyModel: Check that popups inside survey are closed when scrolli
assert.notOk(question.dropdownListModel.popupModel.isVisible);
assert.notOk(model["onScrollCallback"]);
model.onScroll();
});
QUnit.test("Copy panel with invisible questions at design-time", (assert): any => {
const survey = new SurveyModel();
survey.setDesignMode(true);
survey.fromJSON({
elements: [
{ type: "panel", name: "panel1",
elements: [
{ type: "text", name: "q1", visible: false },
{ type: "text", name: "q2" }
]
}
]
});
const panel1 = survey.getPanelByName("panel1");
const panel2 = Serializer.createClass("panel");
panel2.fromJSON(panel1.toJSON());
panel2.name = "panel2";
panel2.questions[0].name = "q3";
panel2.questions[1].name = "q4";
survey.pages[0].addElement(panel2);
const q1 = survey.getQuestionByName("q1");
const q3 = survey.getQuestionByName("q3");
assert.equal(q1.visible, false, "q1.visible = false");
assert.equal(q1.isVisible, true, "q1.isVisible = true");
assert.equal(q1.getPropertyValue("isVisible"), true, "q1.isVisible via getPropertyValue");
assert.equal(q3.visible, false, "q3.visible = false");
assert.equal(q3.isVisible, true, "q3.isVisible = true");
assert.equal(q3.getPropertyValue("isVisible"), true, "q3.isVisible via getPropertyValue");
});

0 comments on commit 7faaec0

Please sign in to comment.