fix w formularzu

This commit is contained in:
Mateusz Gruszczyński
2025-09-26 23:14:57 +02:00
parent 95b01665b9
commit fd46242cf5
2 changed files with 86 additions and 36 deletions

View File

@@ -0,0 +1,43 @@
(function () {
'use strict';
function ready(fn) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fn);
} else {
fn();
}
}
ready(function () {
var boxes = Array.prototype.slice.call(
document.querySelectorAll('input.form-check-input[type="checkbox"][data-group="postepy"]')
);
if (!boxes.length) return;
function atLeastOneChecked() {
return boxes.some(function (b) { return b.checked; });
}
// Blokuj odznaczenie ostatniego włączonego
boxes.forEach(function (box) {
box.addEventListener('change', function () {
if (!atLeastOneChecked()) {
box.checked = true;
}
});
});
// Walidacja przy submit
var form = boxes[0].closest('form');
if (form) {
form.addEventListener('submit', function (e) {
if (!atLeastOneChecked()) {
e.preventDefault();
// Możesz podmienić na toast/flash wg własnego UI
alert('Co najmniej jeden wskaźnik postępu musi być włączony.');
}
});
}
});
})();