fix w formularzu
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// static/js/postepy_guard.js
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
@@ -15,29 +16,56 @@
|
||||
);
|
||||
if (!boxes.length) return;
|
||||
|
||||
var warning = document.getElementById('postepyWarning');
|
||||
|
||||
function atLeastOneChecked() {
|
||||
return boxes.some(function (b) { return b.checked; });
|
||||
}
|
||||
|
||||
// Blokuj odznaczenie ostatniego włączonego
|
||||
function updateWarning() {
|
||||
var show = !atLeastOneChecked();
|
||||
if (warning) {
|
||||
warning.classList.toggle('d-none', !show);
|
||||
if (show) {
|
||||
// delikatny highlight
|
||||
warning.classList.add('animate__animated', 'animate__headShake');
|
||||
setTimeout(function () {
|
||||
warning.classList.remove('animate__animated', 'animate__headShake');
|
||||
}, 700);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Blokuj odznaczenie ostatniego i pokaż ostrzeżenie
|
||||
boxes.forEach(function (box) {
|
||||
box.addEventListener('change', function () {
|
||||
if (!atLeastOneChecked()) {
|
||||
// przywróć zaznaczenie i pokaż ostrzeżenie
|
||||
box.checked = true;
|
||||
updateWarning();
|
||||
// krótka wizualna informacja na samym przycisku
|
||||
box.classList.add('is-invalid');
|
||||
setTimeout(function(){ box.classList.remove('is-invalid'); }, 500);
|
||||
return;
|
||||
}
|
||||
updateWarning();
|
||||
});
|
||||
});
|
||||
|
||||
// Walidacja przy submit
|
||||
// Walidacja przy submit — pokaż blok zamiast alertu
|
||||
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.');
|
||||
updateWarning();
|
||||
// focus na pierwszy przełącznik
|
||||
boxes[0].focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Inicjalny stan
|
||||
updateWarning();
|
||||
});
|
||||
})();
|
||||
|
@@ -297,6 +297,8 @@
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mt-2">
|
||||
|
||||
|
||||
<div class="col-12 col-md-4">
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
@@ -339,7 +341,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="postepyWarning" class="alert alert-warning d-none mt-2" role="alert">
|
||||
Nie można wyłączyć wszystkich wskaźników postępu. Pozostaw przynajmniej jeden włączony.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- CTA -->
|
||||
|
Reference in New Issue
Block a user