Commit 871b5b2
committed
feature #60902 [TwigBridgeRessources] add aria-invalid and aria-describedby on form inputs when validation failure exist (jeanfrancois-morin)
This PR was squashed before being merged into the 7.4 branch.
Discussion
----------
[TwigBridgeRessources] add aria-invalid and aria-describedby on form inputs when validation failure exist
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues |
| License | MIT
## Context and objective
This PR aims to add the appropriate ARIA attributes (`aria-invalid` and `aria-describedby`) to form fields when validation errors are present.
The proposal is based on the recommendations of [WCAG 2.1](https://www.w3.org/TR/WCAG21/#error-identification) and specifically the technique [ARIA21](https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA21), which describes the combined use of `aria-invalid="true"` and `aria-describedby="<TEXT_ERROR_ID>"` AFTER user input validation. It seems particularly relevant to implement this since SymfonyUX's LiveComponent allows for an auto-validation system, enabling real-time error feedback to users as they fill out the form.
Concretely, users of screen readers will be informed of the presence of errors as soon as they focus on the form field, and if an explicit error message is associated, they can access it immediately.
Note that the `aria-describedby` attribute can point to one or more HTML elements, allowing multiple messages (for example, a help message and an error message) to be vocalized. This PR takes this possibility into account by associating each field with the text passages `_field_id_help_` and `_field_id_errors_` when applicable.
## Twig Side
The proposal is integrated into all form themes through the main template `form_div_layout.html.twig`, except for the files `bootstrap_4_layout.html.twig` and `bootstrap_4_horizontal_layout.html.twig`. In these files, errors were initially placed inside the associated label, so it is not necessary to add the `aria-describedby` attribute. Errors will be vocalized automatically and immediately after the label content. The `aria-invalid="true"` attribute remains necessary to indicate the presence of errors.
Let me know if this approach works for you, or if you would like me to modify any aspects.
Commits
-------
6957eba [TwigBridgeRessources] add aria-invalid and aria-describedby on form inputs when validation failure existFile tree
11 files changed
+48
-49
lines changed- src/Symfony/Bridge/Twig
- Resources/views/Form
11 files changed
+48
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 25 | + | |
30 | 26 | | |
31 | 27 | | |
32 | 28 | | |
| |||
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
38 | | - | |
| 34 | + | |
39 | 35 | | |
40 | 36 | | |
41 | 37 | | |
| |||
Lines changed: 3 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 130 | + | |
135 | 131 | | |
136 | 132 | | |
137 | 133 | | |
138 | 134 | | |
139 | 135 | | |
140 | 136 | | |
141 | | - | |
| 137 | + | |
142 | 138 | | |
143 | 139 | | |
144 | 140 | | |
| |||
189 | 185 | | |
190 | 186 | | |
191 | 187 | | |
192 | | - | |
| 188 | + | |
193 | 189 | | |
194 | 190 | | |
195 | 191 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | | - | |
| 287 | + | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
289 | 293 | | |
290 | 294 | | |
291 | 295 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
| |||
68 | 64 | | |
69 | 65 | | |
70 | 66 | | |
71 | | - | |
| 67 | + | |
72 | 68 | | |
73 | 69 | | |
74 | 70 | | |
| |||
Lines changed: 3 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | 327 | | |
332 | 328 | | |
333 | 329 | | |
| |||
340 | 336 | | |
341 | 337 | | |
342 | 338 | | |
343 | | - | |
| 339 | + | |
344 | 340 | | |
345 | 341 | | |
346 | 342 | | |
| |||
353 | 349 | | |
354 | 350 | | |
355 | 351 | | |
356 | | - | |
| 352 | + | |
357 | 353 | | |
358 | 354 | | |
359 | 355 | | |
| |||
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | | - | |
| 347 | + | |
| 348 | + | |
348 | 349 | | |
349 | | - | |
| 350 | + | |
350 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
351 | 366 | | |
352 | 367 | | |
353 | 368 | | |
354 | 369 | | |
355 | 370 | | |
356 | 371 | | |
357 | | - | |
| 372 | + | |
358 | 373 | | |
359 | 374 | | |
360 | 375 | | |
| |||
399 | 414 | | |
400 | 415 | | |
401 | 416 | | |
402 | | - | |
| 417 | + | |
403 | 418 | | |
404 | 419 | | |
405 | 420 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 3 | + | |
8 | 4 | | |
9 | 5 | | |
10 | 6 | | |
| |||
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
18 | | - | |
| 14 | + | |
19 | 15 | | |
20 | 16 | | |
21 | 17 | | |
| |||
Lines changed: 3 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 284 | + | |
289 | 285 | | |
290 | 286 | | |
291 | 287 | | |
| |||
294 | 290 | | |
295 | 291 | | |
296 | 292 | | |
297 | | - | |
| 293 | + | |
298 | 294 | | |
299 | 295 | | |
300 | 296 | | |
| |||
342 | 338 | | |
343 | 339 | | |
344 | 340 | | |
345 | | - | |
346 | | - | |
| 341 | + | |
347 | 342 | | |
348 | 343 | | |
349 | 344 | | |
| |||
0 commit comments