From 83c6bf1f0edf85cdc7da8f3d59b8147513e46e3e Mon Sep 17 00:00:00 2001 From: mfo Date: Tue, 9 Apr 2024 17:36:40 +0200 Subject: [PATCH] feat(Champ.siret): on invalid, set error message on InputStatutErrorMessage. on valid, set info message on siret info component Co-authored-by: Corinne Durrmeyer --- app/components/dsfr/input_errorable.rb | 10 +++++++--- app/components/editable_champ/siret_component.rb | 8 ++++++++ app/views/champs/siret/show.turbo_stream.haml | 9 ++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/components/dsfr/input_errorable.rb b/app/components/dsfr/input_errorable.rb index 1510f210d..c2b394896 100644 --- a/app/components/dsfr/input_errorable.rb +++ b/app/components/dsfr/input_errorable.rb @@ -75,9 +75,9 @@ module Dsfr }.merge(input_error_class_names))) if errors_on_attribute? - @opts.deep_merge!(aria: { - describedby: describedby_id - }) + @opts.deep_merge!(aria: { describedby: describedby_id }) + elsif hintable? + @opts.deep_merge!(aria: { describedby: hint_id }) end if @required @@ -130,6 +130,10 @@ module Dsfr false end + def hintable? + false + end + def hint? return true if get_slot(:hint).present? diff --git a/app/components/editable_champ/siret_component.rb b/app/components/editable_champ/siret_component.rb index 3957c23bb..8997b7c4e 100644 --- a/app/components/editable_champ/siret_component.rb +++ b/app/components/editable_champ/siret_component.rb @@ -2,4 +2,12 @@ class EditableChamp::SiretComponent < EditableChamp::EditableChampBaseComponent def dsfr_input_classname 'fr-input' end + + def hint_id + dom_id(@champ, :siret_info) + end + + def hintable? + true + end end diff --git a/app/views/champs/siret/show.turbo_stream.haml b/app/views/champs/siret/show.turbo_stream.haml index 2e56df6aa..81781577b 100644 --- a/app/views/champs/siret/show.turbo_stream.haml +++ b/app/views/champs/siret/show.turbo_stream.haml @@ -1 +1,8 @@ -= turbo_stream.update dom_id(@champ, :siret_info), partial: 'shared/champs/siret/etablissement', locals: { siret: @siret, etablissement: @champ.etablissement } +- if @champ.etablissement_fetch_error_key.present? + = turbo_stream.update @champ.describedby_id, partial: 'shared/champs/siret/etablissement', locals: { siret: @siret, etablissement: @champ.etablissement } + = turbo_stream.show @champ.describedby_id + = turbo_stream.hide(dom_id(@champ, :siret_info)) +- else + = turbo_stream.update dom_id(@champ, :siret_info), partial: 'shared/champs/siret/etablissement', locals: { siret: @siret, etablissement: @champ.etablissement } + = turbo_stream.show dom_id(@champ, :siret_info) + = turbo_stream.hide(@champ.describedby_id)