From a673fe99f869848cb24a44b84db7aa5879a1925d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 26 Sep 2025 23:19:57 +0200 Subject: [PATCH] fix w formularzu --- static/js/przelaczniki_zabezpieczenie.js | 36 +++++++++++++++++++++--- templates/admin/formularz_zbiorek.html | 8 +++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/static/js/przelaczniki_zabezpieczenie.js b/static/js/przelaczniki_zabezpieczenie.js index 8aeb0bb..a085735 100644 --- a/static/js/przelaczniki_zabezpieczenie.js +++ b/static/js/przelaczniki_zabezpieczenie.js @@ -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(); }); })(); diff --git a/templates/admin/formularz_zbiorek.html b/templates/admin/formularz_zbiorek.html index 9a418a0..3f68e30 100644 --- a/templates/admin/formularz_zbiorek.html +++ b/templates/admin/formularz_zbiorek.html @@ -297,6 +297,8 @@
+ +
- + +
+