Skip to content

Commit

Permalink
Add isMessagePanelVisible property into selectbase question fix #7749 (
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jan 29, 2024
1 parent e266677 commit 590b277
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/question_baseselect.ts
Expand Up @@ -54,7 +54,7 @@ export class QuestionSelectBase extends Question {
});
this.registerPropertyChangedHandlers(
["choicesFromQuestion", "choicesFromQuestionMode", "choiceValuesFromQuestion",
"choiceTextsFromQuestion", "showNoneItem", "isUsingRestful"],
"choiceTextsFromQuestion", "showNoneItem", "isUsingRestful", "isMessagePanelVisible"],
() => {
this.onVisibleChoicesChanged();
}
Expand Down Expand Up @@ -919,7 +919,7 @@ export class QuestionSelectBase extends Question {
protected addToVisibleChoices(items: Array<ItemValue>, isAddAll: boolean): void {
this.headItemsCount = 0;
this.footItemsCount = 0;
if(!this.hasChoicesUrl) {
if(!this.isEmptyActiveChoicesInDesign) {
this.addNewItemToVisibleChoices(items, isAddAll);
}
const dict = new Array<{ index: number, item: ItemValue }>();
Expand Down Expand Up @@ -1079,9 +1079,18 @@ export class QuestionSelectBase extends Question {
(<any>question).addDependedQuestion(this);
return this.getChoicesFromArrayQuestion(question);
}
if(this.isDesignModeV2 && this.hasChoicesUrl) return [];
if(this.isEmptyActiveChoicesInDesign) return [];
return this.choicesFromUrl ? this.choicesFromUrl : this.getChoices();
}
public get isMessagePanelVisible(): boolean {
return this.getPropertyValue("isMessagePanelVisible", false);
}
public set isMessagePanelVisible(val: boolean) {
this.setPropertyValue("isMessagePanelVisible", val);
}
private get isEmptyActiveChoicesInDesign(): boolean {
return this.isDesignModeV2 && (this.hasChoicesUrl || this.isMessagePanelVisible);
}
getCarryForwardQuestion(data?: ISurveyData): Question {
const question = this.findCarryForwardQuestion(data);
const selBaseQuestion = this.getQuestionWithChoicesCore(question);
Expand Down
16 changes: 16 additions & 0 deletions tests/question_baseselecttests.ts
Expand Up @@ -1658,3 +1658,19 @@ QUnit.test("checkbox, selectAll & survey.data, bug#7657", (assert) => {
assert.deepEqual(q.value, ["One", "Two"], "q.value, #2");
assert.deepEqual(survey.data, { q1: ["One", "Two"] }, "survey.data, #2");
});
QUnit.test("Do not show show choices in designer", function(assert) {
settings.supportCreatorV2 = true;
const json = { elements: [
{ type: "checkbox", name: "q1", choices: [1, 2, 3, 4, 5] }
] };
const survey = new SurveyModel();
survey.setDesignMode(true);
survey.fromJSON(json);
const question = <QuestionCheckboxModel>survey.getQuestionByName("q1");
assert.equal(question.visibleChoices.length, 5 + 1 + 3, "Show choices in designer, #1");
question.isMessagePanelVisible = true;
assert.equal(question.visibleChoices.length, 3, "Hide choices in designer, #2");
question.isMessagePanelVisible = false;
assert.equal(question.visibleChoices.length, 5 + 1 + 3, "Show choices in designer, #1");
settings.supportCreatorV2 = false;
});

0 comments on commit 590b277

Please sign in to comment.