Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Panel with Tabbed UI - A new untitled panel displays a weird … #8428

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export class QuestionPanelDynamicModel extends Question
this.createLocalizableString("panelNextText", this, false, "pageNextText");
this.createLocalizableString("noEntriesText", this, false, "noEntriesText");
this.createLocalizableString("templateTabTitle", this, true, "panelDynamicTabTextFormat");
this.createLocalizableString("tabTitlePlaceholder", this, true);
this.registerPropertyChangedHandlers(["panelsState"], () => {
this.setPanelsState();
});
Expand Down Expand Up @@ -426,6 +427,15 @@ export class QuestionPanelDynamicModel extends Question
get locTemplateTabTitle(): LocalizableString {
return this.getLocalizableString("templateTabTitle");
}
public get tabTitlePlaceholder(): string {
return this.locTabTitlePlaceholder.text;
}
public set tabTitlePlaceholder(newValue: string) {
this.locTabTitlePlaceholder.text = newValue;
}
get locTabTitlePlaceholder(): LocalizableString {
return this.getLocalizableString("tabTitlePlaceholder");
}
/**
* A template for panel descriptions.
* @see template
Expand Down Expand Up @@ -2394,6 +2404,9 @@ export class QuestionPanelDynamicModel extends Question

const locTitle = new LocalizableString(panel, true);
locTitle.onGetTextCallback = (str: string): string => {
if(!str) {
str = this.locTabTitlePlaceholder.renderedHtml;
}
if(!this.survey) return str;
const options = {
title: str,
Expand Down Expand Up @@ -2502,6 +2515,8 @@ Serializer.addClass(
{ name: "templateTitle:text", serializationProperty: "locTemplateTitle" },
{ name: "templateTabTitle", serializationProperty: "locTemplateTabTitle",
visibleIf: (obj: any) => { return obj.renderMode === "tab"; } },
{ name: "tabTitlePlaceholder", serializationProperty: "locTabTitlePlaceholder",
visibleIf: (obj: any) => { return obj.renderMode === "tab"; } },
{
name: "templateDescription:text",
serializationProperty: "locTemplateDescription",
Expand Down
30 changes: 30 additions & 0 deletions tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6161,6 +6161,36 @@ QUnit.test("templateVisibleIf & renderMode: tab, additionalTitleToolbar&template
assert.equal(panelTabToolbar.actions[1].locTitle.textOrHtml, "#2-2 a");
assert.equal(panelTabToolbar.actions[2].locTitle.textOrHtml, "#3-3 a");
});
QUnit.test("templateVisibleIf & renderMode: tab, templateTabTitle&tabTitlePlaceholder in JSON", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "paneldynamic",
name: "panel",
templateElements: [
{ type: "text", name: "q1" },
{ type: "text", name: "q2" }
],
panelCount: 2,
renderMode: "tab",
tabTitlePlaceholder: "Empty value",
templateTabTitle: "{panel.q1}"
}],
});
const panel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
const panelTabToolbar = panel.additionalTitleToolbar;
assert.equal(panelTabToolbar.actions.length, 2, "There are two panels");
assert.equal(panelTabToolbar.actions[0].locTitle.textOrHtml, "Empty value", "#1");
assert.equal(panelTabToolbar.actions[1].locTitle.textOrHtml, "Empty value", "#2");
panel.panels[1].getQuestionByName("q1").value = "item2";
assert.equal(panelTabToolbar.actions[0].locTitle.textOrHtml, "Empty value", "#3");
assert.equal(panelTabToolbar.actions[1].locTitle.textOrHtml, "item2", "#4");
panel.panels[0].getQuestionByName("q1").value = "item1";
assert.equal(panelTabToolbar.actions[0].locTitle.textOrHtml, "item1", "#5");
assert.equal(panelTabToolbar.actions[1].locTitle.textOrHtml, "item2", "#6");
panel.panels[1].getQuestionByName("q1").clearValue();
assert.equal(panelTabToolbar.actions[0].locTitle.textOrHtml, "item1", "#7");
assert.equal(panelTabToolbar.actions[1].locTitle.textOrHtml, "Empty value", "#8");
});
QUnit.test("templateVisibleIf & additionalTitleToolbar", function (assert) {
const survey = new SurveyModel({
elements: [
Expand Down
Loading