|
90 | 90 | const allFields = document.querySelectorAll(".field"); |
91 | 91 | const rowTypeField = rowTypeSelect.closest(".field"); |
92 | 92 |
|
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 |
94 | 107 | 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); |
97 | 110 |
|
98 | | - // Always hide all fields except row type select by default |
99 | | - allFields.forEach((field) => { |
100 | | - if (field !== rowTypeField) { |
| 111 | + if (field !== rowTypeField && !isAlwaysVisible) { |
101 | 112 | field.style.display = "none"; |
| 113 | + } else { |
| 114 | + // Ensure the always-visible fields and the selector are displayed |
| 115 | + field.style.display = ""; |
102 | 116 | } |
103 | 117 | }); |
104 | 118 |
|
|
131 | 145 | field.style.display = ""; |
132 | 146 | }); |
133 | 147 | } |
| 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 | + }); |
134 | 176 | } |
135 | 177 |
|
136 | 178 | // Initialize when DOM is fully loaded |
|
0 commit comments