diff --git a/app/components/dsfr/input_component.rb b/app/components/dsfr/input_component.rb index feb1a40c2..39ddd0020 100644 --- a/app/components/dsfr/input_component.rb +++ b/app/components/dsfr/input_component.rb @@ -6,6 +6,8 @@ class Dsfr::InputComponent < ApplicationComponent delegate :object, to: :@form delegate :errors, to: :object + attr_reader :attribute + # use it to indicate detailed about the inputs, ex: https://www.systeme-de-design.gouv.fr/elements-d-interface/modeles-et-blocs-fonctionnels/demande-de-mot-de-passe # it uses aria-describedby on input and link it to yielded content renders_one :describedby diff --git a/app/components/dsfr/input_errorable.rb b/app/components/dsfr/input_errorable.rb index 2da8dee85..91fcfcde2 100644 --- a/app/components/dsfr/input_errorable.rb +++ b/app/components/dsfr/input_errorable.rb @@ -23,7 +23,7 @@ module Dsfr { "#{dsfr_group_classname}--error" => errors_on_attribute?, - "#{dsfr_group_classname}--valid" => !errors_on_attribute? && errors_on_another_attribute? + "#{dsfr_group_classname}--valid" => !errors_on_attribute? && errors_on_another_attribute? && object.public_send(attribute).present? } end @@ -51,9 +51,9 @@ module Dsfr def attribute_or_rich_body case @input_type when :rich_text_area - @attribute.to_s.sub(/\Arich_/, '').to_sym + attribute.to_s.sub(/\Arich_/, '').to_sym else - @attribute + attribute end end diff --git a/app/components/editable_champ/champ_label_component.rb b/app/components/editable_champ/champ_label_component.rb index fac9e4c28..3143ad276 100644 --- a/app/components/editable_champ/champ_label_component.rb +++ b/app/components/editable_champ/champ_label_component.rb @@ -3,6 +3,8 @@ class EditableChamp::ChampLabelComponent < ApplicationComponent include Dsfr::InputErrorable + attr_reader :attribute + def initialize(form:, champ:, seen_at: nil) @form, @champ, @seen_at = form, champ, seen_at @attribute = :value diff --git a/app/components/editable_champ/champ_label_content_component.rb b/app/components/editable_champ/champ_label_content_component.rb index d373b240f..94978c7b0 100644 --- a/app/components/editable_champ/champ_label_content_component.rb +++ b/app/components/editable_champ/champ_label_content_component.rb @@ -4,6 +4,8 @@ class EditableChamp::ChampLabelContentComponent < ApplicationComponent include ApplicationHelper include Dsfr::InputErrorable + attr_reader :attribute + def initialize(form:, champ:, seen_at: nil) @form, @champ, @seen_at = form, champ, seen_at @attribute = :value diff --git a/app/components/editable_champ/editable_champ_base_component.rb b/app/components/editable_champ/editable_champ_base_component.rb index 9d74d9698..5acb853c1 100644 --- a/app/components/editable_champ/editable_champ_base_component.rb +++ b/app/components/editable_champ/editable_champ_base_component.rb @@ -3,6 +3,13 @@ class EditableChamp::EditableChampBaseComponent < ApplicationComponent include Dsfr::InputErrorable + attr_reader :attribute + + def initialize(form:, champ:, seen_at: nil, opts: {}) + @form, @champ, @seen_at, @opts = form, champ, seen_at, opts + @attribute = :value + end + def dsfr_champ_container :div end @@ -14,9 +21,4 @@ class EditableChamp::EditableChampBaseComponent < ApplicationComponent def describedby_id @champ.describedby_id end - - def initialize(form:, champ:, seen_at: nil, opts: {}) - @form, @champ, @seen_at, @opts = form, champ, seen_at, opts - @attribute = :value - end end