diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 194fd3513..98ec37d23 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 41881adf7..0381e9c32 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -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) diff --git a/app/models/champ.rb b/app/models/champ.rb index 552d0676d..aa093ccc5 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -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