Fix CC2r: uncheck not persisting + want_license hiding cc2r when active

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.
This commit is contained in:
Pontoporeia
2026-07-05 14:04:05 +02:00
parent 83e9dd0bc2
commit ec6c939f4e
5 changed files with 30 additions and 22 deletions
+1
View File
@@ -20,3 +20,4 @@
- [x] Replace <details> with <fieldset>/<legend> in cleanup fragments (like contenus.php) - [x] Replace <details> with <fieldset>/<legend> 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] 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] 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
+6 -2
View File
@@ -11,13 +11,17 @@ require_once APP_ROOT . '/src/FragmentRenderer.php';
$licenseTypes = Database::getInstance()->getAllLicenseTypes(); $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', [ FragmentRenderer::render('form/_licence', [
'adminMode' => true, 'adminMode' => true,
'accessTypeId' => $_POST['access_type_id'] ?? '', 'accessTypeId' => $_POST['access_type_id'] ?? '',
'licenseId' => $_POST['license_id'] ?? '', 'licenseId' => $_POST['license_id'] ?? '',
'licenseCustom' => $_POST['license_custom'] ?? '', 'licenseCustom' => $_POST['license_custom'] ?? '',
'cc2r' => !empty($_POST['cc2r']), 'cc2r' => $cc2r,
'wantLicense' => !empty($_POST['want_license']), 'wantLicense' => $wantLicense,
'hxPost' => '/admin/fragments/licence.php', 'hxPost' => '/admin/fragments/licence.php',
'licenseTypes' => $licenseTypes, 'licenseTypes' => $licenseTypes,
]); ]);
+6 -2
View File
@@ -10,13 +10,17 @@ require_once APP_ROOT . '/src/FragmentRenderer.php';
$licenseTypes = Database::getInstance()->getAllLicenseTypes(); $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', [ FragmentRenderer::render('form/_licence', [
'adminMode' => false, 'adminMode' => false,
'accessTypeId' => $_POST['access_type_id'] ?? '', 'accessTypeId' => $_POST['access_type_id'] ?? '',
'licenseId' => $_POST['license_id'] ?? '', 'licenseId' => $_POST['license_id'] ?? '',
'licenseCustom' => $_POST['license_custom'] ?? '', 'licenseCustom' => $_POST['license_custom'] ?? '',
'cc2r' => !empty($_POST['cc2r']), 'cc2r' => $cc2r,
'wantLicense' => !empty($_POST['want_license']), 'wantLicense' => $wantLicense,
'hxPost' => '/partage/fragments/licence.php', 'hxPost' => '/partage/fragments/licence.php',
'licenseTypes' => $licenseTypes, 'licenseTypes' => $licenseTypes,
]); ]);
+3 -2
View File
@@ -35,7 +35,7 @@
<?php <?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes; $name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false; $selected = $licenseId; $placeholder = 'Aucune licence'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php'; include APP_ROOT . '/templates/partials/form/select-field.php';
?> ?>
@@ -54,6 +54,7 @@
<div class="admin-form-group"> <div class="admin-form-group">
<label class="admin-checkbox-label"> <label class="admin-checkbox-label">
<input type="hidden" name="want_license" value="0">
<input type="checkbox" name="want_license" value="1" <input type="checkbox" name="want_license" value="1"
hx-post="<?= $hxPost ?>" hx-post="<?= $hxPost ?>"
hx-target=".licence-license-choice" hx-target=".licence-license-choice"
@@ -77,7 +78,7 @@
<?php <?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes; $name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false; $selected = $licenseId; $placeholder = 'Aucune licence'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php'; include APP_ROOT . '/templates/partials/form/select-field.php';
?> ?>
@@ -119,20 +119,18 @@ $adminMode = $adminMode ?? false;
<p class="licence-note"><em>L'auteur·ice peut, à tout moment, décider de restreindre son propre choix. Iel ne peut par contre pas l'ouvrir.</em></p> <p class="licence-note"><em>L'auteur·ice peut, à tout moment, décider de restreindre son propre choix. Iel ne peut par contre pas l'ouvrir.</em></p>
</div> </div>
<!-- Seed saved licence values for the initial htmx load. <!-- Licence - rendered from stored data on page load; swapped via htmx when radio changes -->
These are overridden by visible inputs inside .licence-license-choice <?php
once htmx renders them - later DOM order wins in POST. --> $initialAccess = array_key_exists('access_type_id', $formData) ? $formData['access_type_id'] : $defaultAccessTypeId;
<input type="hidden" name="license_id" value="<?= htmlspecialchars((string)($formData['license_id'] ?? '')) ?>"> if ($initialAccess === '' || $initialAccess === null) {
<input type="hidden" name="license_custom" value="<?= htmlspecialchars($formData['license_custom'] ?? '') ?>"> $initialAccess = (string)$defaultAccessTypeId;
<input type="hidden" name="cc2r" value="<?= !empty($formData['cc2r']) ? '1' : '' ?>"> }
<?php $wantLicense = !empty($formData['license_id']) || !empty($formData['license_custom']); ?> $cc2r = !empty($formData['cc2r']);
<input type="hidden" name="want_license" value="<?= $wantLicense ? '1' : '' ?>"> $wantLicense = $cc2r || !empty($formData['license_id']) || !empty($formData['license_custom']);
$licenseId = $formData['license_id'] ?? '';
<!-- Licence - swapped via htmx when radio changes --> $licenseCustom = $formData['license_custom'] ?? '';
<div class="licence-license-choice" $accessTypeId = (string)$initialAccess;
hx-post="<?= $adminMode ? '/admin/fragments/licence.php' : '/partage/fragments/licence.php' ?>" $hxPost = $adminMode ? '/admin/fragments/licence.php' : '/partage/fragments/licence.php';
hx-trigger="load" include APP_ROOT . '/templates/partials/form/_licence.php';
hx-include="closest fieldset" ?>
hx-swap="outerHTML">
</div>
</fieldset> </fieldset>