Skip to content

Commit 0ef19a7

Browse files
committed
fieldset display based on inside fields visibility
1 parent cd0e434 commit 0ef19a7

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

src/cs_dynamicpages/browser/static/edit_dynamicpagerow.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,29 @@
9090
const allFields = document.querySelectorAll(".field");
9191
const rowTypeField = rowTypeSelect.closest(".field");
9292

93-
// Show all fields first
93+
// Define default Plone fields that should always be visible
94+
const alwaysVisibleFieldIds = [
95+
"formfield-form-widgets-IExcludeFromNavigation-exclude_from_nav",
96+
"formfield-form-widgets-IShortName-id",
97+
"formfield-form-widgets-IOwnership-creators",
98+
"formfield-form-widgets-IOwnership-contributors",
99+
"formfield-form-widgets-IOwnership-rights",
100+
"formfield-form-widgets-IPublication-effective",
101+
"formfield-form-widgets-IPublication-expires",
102+
"formfield-form-widgets-ICategorization-subjects",
103+
"formfield-form-widgets-ICategorization-language",
104+
];
105+
106+
// Hide all fields except the row type selector and the always-visible ones
94107
allFields.forEach((field) => {
95-
field.style.display = "";
96-
});
108+
// Check if the field is the row type selector or if its ID is in the always-visible list
109+
const isAlwaysVisible = alwaysVisibleFieldIds.includes(field.id);
97110

98-
// Always hide all fields except row type select by default
99-
allFields.forEach((field) => {
100-
if (field !== rowTypeField) {
111+
if (field !== rowTypeField && !isAlwaysVisible) {
101112
field.style.display = "none";
113+
} else {
114+
// Ensure the always-visible fields and the selector are displayed
115+
field.style.display = "";
102116
}
103117
});
104118

@@ -131,6 +145,34 @@
131145
field.style.display = "";
132146
});
133147
}
148+
149+
// After toggling fields, check for empty fieldsets and hide them
150+
updateFieldsetAndTabVisibility();
151+
}
152+
153+
function updateFieldsetAndTabVisibility() {
154+
const allFieldsets = document.querySelectorAll("fieldset");
155+
const allTabLinks = document.querySelectorAll("a.autotoc-level-1");
156+
157+
allFieldsets.forEach((fieldset, index) => {
158+
// Find all direct .field children that are currently visible
159+
const visibleFields = fieldset.querySelectorAll(
160+
".field:not([style*='display: none'])"
161+
);
162+
163+
const hasVisibleFields = Array.from(visibleFields).some(
164+
(field) => field.style.display !== "none"
165+
);
166+
167+
// Hide or show the fieldset based on whether it has visible fields
168+
fieldset.style.display = hasVisibleFields ? "" : "none";
169+
170+
// Also hide/show the corresponding autotoc tab/link based on its order
171+
const tabLink = allTabLinks[index];
172+
if (tabLink) {
173+
tabLink.style.display = hasVisibleFields ? "" : "none";
174+
}
175+
});
134176
}
135177

136178
// Initialize when DOM is fully loaded

0 commit comments

Comments
 (0)