From fd46242cf5e6eafb796d3b4b614a0754ad80b103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 26 Sep 2025 23:14:57 +0200 Subject: [PATCH] fix w formularzu --- static/js/przelaczniki_zabezpieczenie.js | 43 +++++++++++++ templates/admin/formularz_zbiorek.html | 79 +++++++++++++----------- 2 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 static/js/przelaczniki_zabezpieczenie.js diff --git a/static/js/przelaczniki_zabezpieczenie.js b/static/js/przelaczniki_zabezpieczenie.js new file mode 100644 index 0000000..8aeb0bb --- /dev/null +++ b/static/js/przelaczniki_zabezpieczenie.js @@ -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.'); + } + }); + } + }); +})(); diff --git a/templates/admin/formularz_zbiorek.html b/templates/admin/formularz_zbiorek.html index a000ca4..9a418a0 100644 --- a/templates/admin/formularz_zbiorek.html +++ b/templates/admin/formularz_zbiorek.html @@ -297,44 +297,50 @@
-
-
- - -
-
-
-
- - -
-
-
-
- - -
+
+
+ +
-
+ +
+
+ + +
+
+ +
+
+ + +
+
+
+ +
@@ -356,4 +362,5 @@ + {% endblock %}