Use aria-describedby to link notice and input again

https://www.w3.org/WAI/tutorials/forms/instructions/#using-aria-describedby
This commit is contained in:
simon lehericey 2019-11-20 20:47:36 +01:00
parent 84b125d272
commit bc85e9b7ec
3 changed files with 9 additions and 2 deletions

View file

@ -25,4 +25,10 @@ module ChampHelper
end
simple_format(auto_linked_text, {}, sanitize: false)
end
def describedby_id(champ)
if champ.description.present?
"desc-#{champ.type_de_champ.id}-#{champ.row}"
end
end
end

View file

@ -8,4 +8,4 @@
= "modifié le #{try_format_datetime(champ.updated_at)}"
- if champ.description.present?
.notice= string_to_html(champ.description)
.notice{ id: describedby_id(champ) }= string_to_html(champ.description)

View file

@ -1,3 +1,4 @@
= form.text_field :value,
placeholder: champ.libelle,
required: champ.mandatory?
required: champ.mandatory?,
aria: { describedby: describedby_id(champ) }