fix w formularzu
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// static/js/postepy_guard.js
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -15,29 +16,56 @@
|
|||||||
);
|
);
|
||||||
if (!boxes.length) return;
|
if (!boxes.length) return;
|
||||||
|
|
||||||
|
var warning = document.getElementById('postepyWarning');
|
||||||
|
|
||||||
function atLeastOneChecked() {
|
function atLeastOneChecked() {
|
||||||
return boxes.some(function (b) { return b.checked; });
|
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) {
|
boxes.forEach(function (box) {
|
||||||
box.addEventListener('change', function () {
|
box.addEventListener('change', function () {
|
||||||
if (!atLeastOneChecked()) {
|
if (!atLeastOneChecked()) {
|
||||||
|
// przywróć zaznaczenie i pokaż ostrzeżenie
|
||||||
box.checked = true;
|
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');
|
var form = boxes[0].closest('form');
|
||||||
if (form) {
|
if (form) {
|
||||||
form.addEventListener('submit', function (e) {
|
form.addEventListener('submit', function (e) {
|
||||||
if (!atLeastOneChecked()) {
|
if (!atLeastOneChecked()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Możesz podmienić na toast/flash wg własnego UI
|
updateWarning();
|
||||||
alert('Co najmniej jeden wskaźnik postępu musi być włączony.');
|
// focus na pierwszy przełącznik
|
||||||
|
boxes[0].focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inicjalny stan
|
||||||
|
updateWarning();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@@ -297,6 +297,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row g-3 mt-2">
|
<div class="row g-3 mt-2">
|
||||||
|
|
||||||
|
|
||||||
<div class="col-12 col-md-4">
|
<div class="col-12 col-md-4">
|
||||||
<div class="form-check form-switch">
|
<div class="form-check form-switch">
|
||||||
<input
|
<input
|
||||||
@@ -339,7 +341,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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 -->
|
<!-- CTA -->
|
||||||
|
Reference in New Issue
Block a user