From bdcaabd36b079b2e4dbaf3e362d19338ac9dad32 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Tue, 22 Oct 2024 12:06:48 +0200 Subject: [PATCH 01/21] Create unique form field id for templating --- src/Tags/Concerns/RendersForms.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tags/Concerns/RendersForms.php b/src/Tags/Concerns/RendersForms.php index cedf943d6f..47ca921fc5 100644 --- a/src/Tags/Concerns/RendersForms.php +++ b/src/Tags/Concerns/RendersForms.php @@ -142,6 +142,7 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate ->filter()->all(); $data = array_merge($configDefaults, $field->toArray(), [ + 'id' => $field->form()->handle().'-form-' . $field->handle().'-field', 'instructions' => $field->instructions(), 'error' => $errors->first($field->handle()) ?: null, 'default' => $field->value() ?? $field->defaultValue(), From 5b3126927c773e6cf4c26a6debec30009cef833c Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Tue, 22 Oct 2024 12:07:53 +0200 Subject: [PATCH 02/21] Add id attributes to form fields and labels --- resources/views/extend/forms/fields.antlers.html | 2 +- resources/views/extend/forms/fields/assets.antlers.html | 1 + resources/views/extend/forms/fields/default.antlers.html | 1 + resources/views/extend/forms/fields/dictionary.antlers.html | 1 + resources/views/extend/forms/fields/files.antlers.html | 1 + resources/views/extend/forms/fields/select.antlers.html | 1 + resources/views/extend/forms/fields/text.antlers.html | 1 + resources/views/extend/forms/fields/textarea.antlers.html | 1 + resources/views/extend/forms/fields/toggle.antlers.html | 1 + 9 files changed, 9 insertions(+), 1 deletion(-) diff --git a/resources/views/extend/forms/fields.antlers.html b/resources/views/extend/forms/fields.antlers.html index 751f9e0d3d..a337282246 100644 --- a/resources/views/extend/forms/fields.antlers.html +++ b/resources/views/extend/forms/fields.antlers.html @@ -1,6 +1,6 @@ {{ fields }}
- +
{{ field }}
{{ if error }}

{{ error }}

diff --git a/resources/views/extend/forms/fields/assets.antlers.html b/resources/views/extend/forms/fields/assets.antlers.html index 0f0aa3c0c4..6563a55336 100644 --- a/resources/views/extend/forms/fields/assets.antlers.html +++ b/resources/views/extend/forms/fields/assets.antlers.html @@ -1,6 +1,7 @@ Date: Tue, 22 Oct 2024 12:11:26 +0200 Subject: [PATCH 03/21] Add unique ids to multi-select inputs --- resources/views/extend/forms/fields/checkboxes.antlers.html | 6 ++++++ resources/views/extend/forms/fields/radio.antlers.html | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/resources/views/extend/forms/fields/checkboxes.antlers.html b/resources/views/extend/forms/fields/checkboxes.antlers.html index d709da4ead..b14f95400e 100644 --- a/resources/views/extend/forms/fields/checkboxes.antlers.html +++ b/resources/views/extend/forms/fields/checkboxes.antlers.html @@ -5,9 +5,15 @@ type="checkbox" name="{{ handle }}[]" value="{{ option }}" + id="{{ id }}-{{ option | slugify }}-option" {{ if js_driver }}{{ js_attributes }}{{ /if }} {{ if value|in_array:option }}checked{{ /if }} {{ if validate|contains:required }}required{{ /if }} + {{ if error }} + aria-invalid="true" aria-describedby="{{ id }}-error" + {{ elseif instructions }} + aria-describedby="{{ id }}-instructions" + {{ /if }} > {{ label !== null ? label : option }} diff --git a/resources/views/extend/forms/fields/radio.antlers.html b/resources/views/extend/forms/fields/radio.antlers.html index b43998f239..dbd1c4972f 100644 --- a/resources/views/extend/forms/fields/radio.antlers.html +++ b/resources/views/extend/forms/fields/radio.antlers.html @@ -4,9 +4,15 @@ type="radio" name="{{ handle }}" value="{{ option }}" + id="{{ id }}-{{ option | slugify }}-option" {{ if js_driver }}{{ js_attributes }}{{ /if }} {{ if value == option }}checked{{ /if }} {{ if validate|contains:required }}required{{ /if }} + {{ if error }} + aria-invalid="true" aria-describedby="{{ id }}-error" + {{ elseif instructions }} + aria-describedby="{{ id }}-instructions" + {{ /if }} > {{ label !== null ? label : option }} From 0da35ea9346203d2accf4cfbe1994d440108d598 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Tue, 22 Oct 2024 12:12:12 +0200 Subject: [PATCH 04/21] Display field instructions --- resources/views/extend/forms/fields.antlers.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/views/extend/forms/fields.antlers.html b/resources/views/extend/forms/fields.antlers.html index a337282246..eed8e0a182 100644 --- a/resources/views/extend/forms/fields.antlers.html +++ b/resources/views/extend/forms/fields.antlers.html @@ -2,6 +2,9 @@
{{ field }}
+ {{ if instructions }} +

{{ instructions }}

+ {{ /if }} {{ if error }}

{{ error }}

{{ /if }} From 06957284c4de28653379b00ae73283cf2b4446ff Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Tue, 22 Oct 2024 12:12:24 +0200 Subject: [PATCH 05/21] Render field error with id and in red --- resources/views/extend/forms/fields.antlers.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/extend/forms/fields.antlers.html b/resources/views/extend/forms/fields.antlers.html index eed8e0a182..84de2fab6e 100644 --- a/resources/views/extend/forms/fields.antlers.html +++ b/resources/views/extend/forms/fields.antlers.html @@ -6,7 +6,7 @@

{{ instructions }}

{{ /if }} {{ if error }} -

{{ error }}

+

{{ error }}

{{ /if }}
{{ /fields }} From 2c397e0de3c279a9890a7919a92037918ee19d95 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Tue, 22 Oct 2024 12:12:42 +0200 Subject: [PATCH 06/21] Link fields with instructions and error messages --- resources/views/extend/forms/fields/assets.antlers.html | 5 +++++ resources/views/extend/forms/fields/default.antlers.html | 5 +++++ resources/views/extend/forms/fields/dictionary.antlers.html | 5 +++++ resources/views/extend/forms/fields/files.antlers.html | 5 +++++ resources/views/extend/forms/fields/select.antlers.html | 5 +++++ resources/views/extend/forms/fields/text.antlers.html | 5 +++++ resources/views/extend/forms/fields/textarea.antlers.html | 5 +++++ resources/views/extend/forms/fields/toggle.antlers.html | 5 +++++ 8 files changed, 40 insertions(+) diff --git a/resources/views/extend/forms/fields/assets.antlers.html b/resources/views/extend/forms/fields/assets.antlers.html index 6563a55336..d3a3a6ba30 100644 --- a/resources/views/extend/forms/fields/assets.antlers.html +++ b/resources/views/extend/forms/fields/assets.antlers.html @@ -5,4 +5,9 @@ {{ if js_driver }}{{ js_attributes }}{{ /if }} {{ if max_files !== 1 }}multiple{{ /if }} {{ if validate|contains:required }}required{{ /if }} + {{ if error }} + aria-invalid="true" aria-describedby="{{ id }}-error" + {{ elseif instructions }} + aria-describedby="{{ id }}-instructions" + {{ /if }} > diff --git a/resources/views/extend/forms/fields/default.antlers.html b/resources/views/extend/forms/fields/default.antlers.html index 87b2d545fa..79ceb4864c 100644 --- a/resources/views/extend/forms/fields/default.antlers.html +++ b/resources/views/extend/forms/fields/default.antlers.html @@ -7,4 +7,9 @@ {{ if character_limit }}maxlength="{{ character_limit }}"{{ /if }} {{ if js_driver }}{{ js_attributes }}{{ /if }} {{ if validate|contains:required }}required{{ /if }} + {{ if error }} + aria-invalid="true" aria-describedby="{{ id }}-error" + {{ elseif instructions }} + aria-describedby="{{ id }}-instructions" + {{ /if }} > diff --git a/resources/views/extend/forms/fields/dictionary.antlers.html b/resources/views/extend/forms/fields/dictionary.antlers.html index a6a5d74777..244aea45c5 100644 --- a/resources/views/extend/forms/fields/dictionary.antlers.html +++ b/resources/views/extend/forms/fields/dictionary.antlers.html @@ -4,6 +4,11 @@ {{ if js_driver }}{{ js_attributes }}{{ /if }} {{ if multiple }}multiple{{ /if }} {{ if validate|contains:required }}required{{ /if }} + {{ if error }} + aria-invalid="true" aria-describedby="{{ id }}-error" + {{ elseif instructions }} + aria-describedby="{{ id }}-instructions" + {{ /if }} > {{ unless multiple }}