From ec6c939f4ec831654f15e52b364da14e096fb05c Mon Sep 17 00:00:00 2001 From: Pontoporeia Date: Sun, 5 Jul 2026 13:02:44 +0200 Subject: [PATCH] Fix CC2r: uncheck not persisting + want_license hiding cc2r when active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue 1 — hidden seeds overriding user input: Removed all hidden seed inputs (cc2r, want_license, license_id, license_custom). The .licence-license-choice div is now rendered directly from $formData on page load instead of via HTMX load trigger. This eliminates stale-seed interference on both HTMX radio changes and full form submits. Issue 2 — Interne want_license uncheck clearing CC2r: When want_license is unchecked, CC2r and licence selections are cleared (section hidden). Added hidden want_license=0 so the fragment handler can distinguish "arriving from another access type" (no want_license in POST → preserve values) from "explicit Interne toggle" (want_license present → clear CC2r if off). CC2r is independently toggleable within the visible section. Licence dropdown placeholder changed to 'Aucune licence' for an explicit no-licence choice. --- TODO.md | 1 + app/public/admin/fragments/licence.php | 8 +++-- app/public/partage/fragments/licence.php | 8 +++-- app/templates/partials/form/_licence.php | 5 ++-- .../form/fieldset-licence-explanation.php | 30 +++++++++---------- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/TODO.md b/TODO.md index 792a118..98d1753 100644 --- a/TODO.md +++ b/TODO.md @@ -20,3 +20,4 @@ - [x] Replace
with
/ in cleanup fragments (like contenus.php) - [x] Standardise test group recipes: lint-php, lint-css, lint-js, test + add fix recipe + make lint pass clean - [x] Remove Mot de passe column from acces.php, add key.svg icon button in Actions to copy password to clipboard, reorder actions (URL/password/edit/toggle/archive), switch URL icon to link-simple.svg +- [x] Fix CC2r: removed hidden seeds (were stale/overriding user input), render initial licence-choice from \$formData; Interne want_license unchecked clears CC2r+licence, switching from other modes preserves values; CC2r independent toggle; licence dropdown has no-licence placeholder diff --git a/app/public/admin/fragments/licence.php b/app/public/admin/fragments/licence.php index 70d65da..31710c3 100644 --- a/app/public/admin/fragments/licence.php +++ b/app/public/admin/fragments/licence.php @@ -11,13 +11,17 @@ require_once APP_ROOT . '/src/FragmentRenderer.php'; $licenseTypes = Database::getInstance()->getAllLicenseTypes(); +$fromInterne = array_key_exists('want_license', $_POST); +$wantLicense = $fromInterne ? !empty($_POST['want_license']) : (!empty($_POST['cc2r']) || !empty($_POST['license_id']) || !empty($_POST['license_custom'])); +$cc2r = ($fromInterne && !$wantLicense) ? false : !empty($_POST['cc2r']); + FragmentRenderer::render('form/_licence', [ 'adminMode' => true, 'accessTypeId' => $_POST['access_type_id'] ?? '', 'licenseId' => $_POST['license_id'] ?? '', 'licenseCustom' => $_POST['license_custom'] ?? '', - 'cc2r' => !empty($_POST['cc2r']), - 'wantLicense' => !empty($_POST['want_license']), + 'cc2r' => $cc2r, + 'wantLicense' => $wantLicense, 'hxPost' => '/admin/fragments/licence.php', 'licenseTypes' => $licenseTypes, ]); diff --git a/app/public/partage/fragments/licence.php b/app/public/partage/fragments/licence.php index 6de8404..71ea72f 100644 --- a/app/public/partage/fragments/licence.php +++ b/app/public/partage/fragments/licence.php @@ -10,13 +10,17 @@ require_once APP_ROOT . '/src/FragmentRenderer.php'; $licenseTypes = Database::getInstance()->getAllLicenseTypes(); +$fromInterne = array_key_exists('want_license', $_POST); +$wantLicense = $fromInterne ? !empty($_POST['want_license']) : (!empty($_POST['cc2r']) || !empty($_POST['license_id']) || !empty($_POST['license_custom'])); +$cc2r = ($fromInterne && !$wantLicense) ? false : !empty($_POST['cc2r']); + FragmentRenderer::render('form/_licence', [ 'adminMode' => false, 'accessTypeId' => $_POST['access_type_id'] ?? '', 'licenseId' => $_POST['license_id'] ?? '', 'licenseCustom' => $_POST['license_custom'] ?? '', - 'cc2r' => !empty($_POST['cc2r']), - 'wantLicense' => !empty($_POST['want_license']), + 'cc2r' => $cc2r, + 'wantLicense' => $wantLicense, 'hxPost' => '/partage/fragments/licence.php', 'licenseTypes' => $licenseTypes, ]); diff --git a/app/templates/partials/form/_licence.php b/app/templates/partials/form/_licence.php index f4264c4..0988509 100644 --- a/app/templates/partials/form/_licence.php +++ b/app/templates/partials/form/_licence.php @@ -35,7 +35,7 @@ @@ -54,6 +54,7 @@
- - - - - - - - -
-
+ +