Skip to content

Commit 50aeca0

Browse files
petschkithet
authored andcommitted
fix(pat autotoc): Show required indicator for tabs with reuqired multi-checkbox or radio button fields.
A groupt of multiple required checkboxes for a single field are rendered in Plone currently without the required attribute. The same goes for radio buttons. Instead the label is marked as required. This PR supports this situation and also marks the tab-navigation as required, if a field label is marked as required.`
1 parent 112ff1f commit 50aeca0

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/pat/autotoc/autotoc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export default Base.extend({
146146
}
147147

148148
for (const tab of this.tabs) {
149-
if (tab.section.querySelectorAll("[required]").length > 0) {
149+
if (
150+
tab.section.querySelectorAll(
151+
"label.required, label .required, [required]",
152+
).length > 0
153+
) {
150154
tab.nav.classList.add("required");
151155
} else {
152156
tab.nav.classList.remove("required");

src/pat/autotoc/autotoc.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,41 @@ describe("2 - AutoTOC with tabs", function () {
265265
expect(spy_validation_marker).toHaveBeenCalledTimes(1);
266266
jest.restoreAllMocks();
267267
});
268+
269+
it.skip("2.3 - Also set required for checkboxes or radio buttons, where no required attribute might be set on the input itself but instead on or near the label.", async function () {
270+
document.body.innerHTML = `
271+
<form class="pat-validation pat-autotoc"
272+
data-pat-autotoc="
273+
levels: legend;
274+
section: fieldset;
275+
className: autotabs;
276+
validationDelay: 0;
277+
"
278+
>
279+
<fieldset id="fieldset-1">
280+
<legend>Tab 1</legend>
281+
<label class="required">Input 1</label>
282+
</fieldset>
283+
284+
<fieldset id="fieldset-2">
285+
<legend>Tab 2</legend>
286+
<label>Input 2 <span class="required"/></label>
287+
</fieldset>
288+
289+
<fieldset id="fieldset-3">
290+
<legend>Tab 3</legend>
291+
</fieldset>
292+
</form>
293+
`;
294+
295+
registry.scan(document.body);
296+
await utils.timeout(1);
297+
298+
const tabs = document.querySelectorAll(".autotoc-nav > a");
299+
expect(tabs.length).toEqual(3);
300+
301+
expect(tabs[0].classList.contains("required")).toEqual(true);
302+
expect(tabs[1].classList.contains("required")).toEqual(true);
303+
expect(tabs[2].classList.contains("required")).toEqual(false);
304+
});
268305
});

0 commit comments

Comments
 (0)