mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Add field-level aria-errormessage, aria-invalid, and aria-describedby across the TFE form
WCAG 3.3.1 (Error Identification): failing fields now get aria-errormessage pointing to the flash-error container and aria-invalid="true". WCAG 3.3.3 (Error Suggestion): <small> hint text on inputs, selects, and file fields is now linked via aria-describedby (always, not just on error). Changes: - text-field.php, select-field.php, checkbox-list.php: accept $errorFieldName; add aria-errormessage/aria-invalid on match; add id to <small> and aria-describedby on the control - fieldset-tfe-info.php: aria-invalid on synopsis textarea - fichiers-fragment.php: aria-describedby on cover, note d'intention, TFE, annexes, and website inputs; aria-invalid on format checkboxes when error matches 'formats' - form.php: id="flash-error" + tabindex="-1" on flash-error div; accept $errorFieldName from callers - admin/add.php: set $errorFieldName, wire $withAutofocusFn (was identity default) - admin/edit.php: set $errorFieldName - partage/index.php: consume autofocus field, wire autofocus function, add App::flashAutofocus() in submit catch block Also fixes WCAG standards issue: removed invalid 'required' HTML attribute from <fieldset> elements in checkbox-list.php and fichiers-fragment.php (only aria-required stays). Added role="group" for explicit ARIA semantics.
This commit is contained in:
@@ -338,10 +338,13 @@ function renderShareLinkForm(string $slug, array $link): void
|
||||
$pageTitle = 'Soumettre un TFE';
|
||||
$isVerified = !empty($_SESSION['share_verified_' . $slug]);
|
||||
|
||||
// WCAG 3.3.1: which field has a validation error (set by submit handler via App::flashAutofocus)
|
||||
$errorFieldName = App::consumeAutofocus();
|
||||
|
||||
// Build old()-compatible callable from $formData (share forms use the array variant).
|
||||
$shareOldFn = fn(string $key, string $default = '') => old($formData, $key, $default);
|
||||
// No autofocus in the share form - identity function.
|
||||
$shareWithAutofocusFn = fn(string $field, array $attrs = []) => $attrs;
|
||||
// Autofocus function for the share form
|
||||
$shareWithAutofocusFn = fn(string $field, array $attrs = []) => ($errorFieldName === $field) ? ($attrs + ['autofocus' => true]) : $attrs;
|
||||
|
||||
// Load all form help blocks in one query.
|
||||
$helpBlocks = Database::getInstance()->getAllFormHelpBlocks();
|
||||
@@ -647,6 +650,12 @@ function handleShareLinkSubmission(string $slug): void
|
||||
storePrimedFiles($slug);
|
||||
$_SESSION[$shareCsrfKey] = bin2hex(random_bytes(32)); // Regenerate token
|
||||
|
||||
// WCAG 3.3.1: autofocus the failing field after redirect
|
||||
$autofocusField = ThesisCreateController::autofocusFieldForError($e->getMessage());
|
||||
if ($autofocusField !== null) {
|
||||
App::flashAutofocus($autofocusField);
|
||||
}
|
||||
|
||||
// Redirect back to the form
|
||||
header('Location: /partage/' . urlencode($slug));
|
||||
exit();
|
||||
|
||||
Reference in New Issue
Block a user