a11y(champs): expose ids for UI on champ
This commit is contained in:
parent
5f179676c8
commit
fc058f721d
3 changed files with 21 additions and 7 deletions
|
@ -50,7 +50,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def render_champ(champ)
|
||||
champ_selector = ".editable-champ[data-champ-id=\"#{champ.id}\"]"
|
||||
champ_selector = "##{champ.input_group_id}"
|
||||
form_html = render 'shared/dossiers/edit', dossier: champ.dossier, apercu: false
|
||||
champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s
|
||||
# rubocop:disable Rails/OutputSafety
|
||||
|
|
|
@ -20,12 +20,6 @@ module ChampHelper
|
|||
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
|
||||
|
||||
def auto_attach_url(form, object)
|
||||
if object.is_a?(Champ) && object.persisted? && object.public?
|
||||
champs_piece_justificative_url(object.id)
|
||||
|
|
|
@ -139,6 +139,22 @@ class Champ < ApplicationRecord
|
|||
true
|
||||
end
|
||||
|
||||
def input_group_id
|
||||
"champ-#{html_id}"
|
||||
end
|
||||
|
||||
def input_id
|
||||
"#{html_id}-input"
|
||||
end
|
||||
|
||||
def labelledby_id
|
||||
"#{html_id}-label"
|
||||
end
|
||||
|
||||
def describedby_id
|
||||
"#{html_id}-description" if description.present?
|
||||
end
|
||||
|
||||
def stable_id
|
||||
type_de_champ.stable_id
|
||||
end
|
||||
|
@ -159,6 +175,10 @@ class Champ < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def html_id
|
||||
"#{stable_id}-#{id}"
|
||||
end
|
||||
|
||||
def needs_dossier_id?
|
||||
!dossier_id && parent_id
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue