Files
xamxam/app/public/assets/js/app/form-jury-fields.js
T
Pontoporeia 3e93150c76 justfile: standardise test recipes to lint-php/lint-css/lint-js/test + add fix recipe
- Removed ambiguous aliases: phpstan, cs-check, syntax
- Split lint-biome into lint-css and lint-js with correct paths
- Added lint meta-recipe and fix recipe (biome --unsafe + php-cs-fixer)
- Fixed FormBootstrap dead null check, CSS shorthand override bug
- Updated phpstan baseline, suppressed noDescendingSpecificity/noInnerDeclarations
- Applied ~74 biome auto-fixes across CSS/JS
2026-07-05 11:07:41 +02:00

73 lines
2.5 KiB
JavaScript

/**
* form-jury-fields.js — Jury fieldset helpers: dynamic row add/remove and ULB
* promoteur conditional toggle (based on finality selection).
*
* Reads `data-admin-mode` (0/1) from the jury <fieldset>.
*/
(() => {
// ── Dynamic row add/remove ──────────────────────────────────────────────
window.addJuryRow = (listId, inputName, roleLabel) => {
var list = document.getElementById(listId);
if (!list) return;
var n = list.querySelectorAll(".admin-jury-entry").length + 1;
var div = document.createElement("div");
div.className = "admin-jury-entry";
div.innerHTML =
'<input type="text" name="' +
inputName +
'" placeholder="Nom" autocomplete="off" aria-label="' +
roleLabel +
" " +
n +
' \u2014 nom">' +
'<button type="button" class="btn btn--sm btn--ghost admin-btn-remove" onclick="removeJuryRow(this)" aria-label="Supprimer">' +
'<span aria-hidden="true">\u2715</span></button>';
list.appendChild(div);
};
window.removeJuryRow = (btn) => {
var entry = btn.closest(".admin-jury-entry");
if (entry) entry.remove();
};
// ── ULB toggle ─────────────────────────────────────────────────────────
var juryFieldset = document.querySelector("fieldset[data-admin-mode]");
var adminMode = juryFieldset
? juryFieldset.getAttribute("data-admin-mode") === "1"
: false;
try {
var finalitySelect = document.querySelector('select[name="finality"]');
var ulbRow = document.getElementById("jury-promoteur-ulb-row");
if (!finalitySelect || !ulbRow) return;
var ulbAsterisk = document.getElementById("jury-ulb-asterisk");
function isApprofondiSelected() {
var opt = finalitySelect.options[finalitySelect.selectedIndex];
if (!opt) return false;
return (opt.textContent || opt.text || "")
.toLowerCase()
.includes("approfondi");
}
function toggleUlb() {
var show = isApprofondiSelected();
ulbRow.style.display = show ? "" : "none";
if (ulbAsterisk) ulbAsterisk.style.display = show ? "" : "none";
var inputs = ulbRow.querySelectorAll(
'input[name="jury_promoteur_ulb_name[]"]',
);
inputs.forEach((inp, idx) => {
inp.required = adminMode ? false : show && idx === 0;
inp.disabled = !show;
if (!show) inp.value = "";
});
}
finalitySelect.addEventListener("change", toggleUlb);
toggleUlb();
} catch (e) {
console.error("jury ULB toggle:", e);
}
})();