diff --git a/app/components/dsfr/input_errorable.rb b/app/components/dsfr/input_errorable.rb index b5f1a7d94..c648a7bdc 100644 --- a/app/components/dsfr/input_errorable.rb +++ b/app/components/dsfr/input_errorable.rb @@ -21,22 +21,78 @@ module Dsfr end end - def input_group_error_class_names - if @champ && @champ.legend_label? - { - "fr-fieldset--error": errors_on_attribute?, - "fr-fieldset--valid": !errors_on_attribute? && errors_on_another_attribute? - } + def fr_select? + return false if fr_fieldset? + + [ + 'departements', + 'drop_down_list', + 'multiple_drop_down_list', + 'pays', + 'regions' + ].include?(@champ.type_champ) + end + + def fr_input? + [ + 'annuaire_education', + 'date', + 'datetime', + 'decimal_number', + 'dgfip', + 'dossier_link', + 'email', + 'iban', + 'integer_number', + 'mesri', + 'number', + 'phone', + 'piece_justificative', + 'pole_emploi', + 'rna', + 'siret', + 'text', + 'textarea', + 'titre_identite' + ].include?(@champ.type_champ) + end + + def fr_radio? + [ + 'boolean' + ].include?(@champ.type_champ) + end + + def fr_fieldset? + @champ.dsfr_champ_container == :fieldset + end + + def dsfr_group_classname + if fr_fieldset? + dsfr_input_classname else - { - "fr-input-group--error": errors_on_attribute?, - "fr-input-group--valid": !errors_on_attribute? && errors_on_another_attribute? - } + "#{dsfr_input_classname}-group" end end + def dsfr_input_classname + return "fr-fieldset" if fr_fieldset? + return "fr-input" if fr_input? + return "fr-select" if fr_select? + return "fr-radio" if fr_radio? + end + + def input_group_error_class_names + { + "#{dsfr_group_classname}--error" => errors_on_attribute?, + "#{dsfr_group_classname}--valid" => !errors_on_attribute? && errors_on_another_attribute? + } + end + def input_error_class_names - { 'fr-input--error': errors_on_attribute? } + { + "#{dsfr_input_classname}--error": errors_on_attribute? + } end def input_error_opts diff --git a/app/components/dsfr/input_status_message_component/input_status_message_component.html.haml b/app/components/dsfr/input_status_message_component/input_status_message_component.html.haml index 5b745b4dc..2fda4e477 100644 --- a/app/components/dsfr/input_status_message_component/input_status_message_component.html.haml +++ b/app/components/dsfr/input_status_message_component/input_status_message_component.html.haml @@ -1,3 +1,3 @@ -.fr-messages-group{ id: @describedby_id } +.fr-messages-group{ id: @describedby_id } - @error_full_messages.each do |error_message| - %p{ class: class_names('fr-message' => true, "fr-message--#{@errors_on_attribute ? 'error' : 'valid'}" => true)}= error_message + %p{ class: class_names('fr-message' => true, "fr-message--#{@errors_on_attribute ? 'error' : 'valid'}" => true) }= error_message diff --git a/app/components/editable_champ/communes_component/communes_component.html.haml b/app/components/editable_champ/communes_component/communes_component.html.haml index fa297cf12..6cda26370 100644 --- a/app/components/editable_champ/communes_component/communes_component.html.haml +++ b/app/components/editable_champ/communes_component/communes_component.html.haml @@ -8,7 +8,7 @@ .fr-fieldset__element.fr-mb-0 - if commune_options.empty? - - #noop + - # noop - elsif commune_options.size <= 3 %fieldset.fr-fieldset .fr-fieldset__legend--regular.fr-fieldset__legend= t('.commune').html_safe diff --git a/app/components/editable_champ/editable_champ_component.rb b/app/components/editable_champ/editable_champ_component.rb index 2494a3e90..28c9cace1 100644 --- a/app/components/editable_champ/editable_champ_component.rb +++ b/app/components/editable_champ/editable_champ_component.rb @@ -22,47 +22,6 @@ class EditableChamp::EditableChampComponent < ApplicationComponent "EditableChamp::#{@champ.type_champ.camelcase}Component".constantize end - def select_group - [ - 'departements', - 'drop_down_list', - 'epci', - 'pays', - 'regions' - ] - end - - def input_group - [ - 'annuaire_education', - 'date', - 'datetime', - 'decimal_number', - 'dgfip', - 'dossier_link', - 'email', - 'iban', - 'integer_number', - 'mesri', - 'number', - 'phone', - 'piece_justificative', - 'pole_emploi', - 'rna', - 'siret', - 'text', - 'textarea', - 'titre_identite' - ] - end - - def radio_group - [ - 'boolean', - 'yes_no' - ] - end - def html_options { class: class_names( @@ -70,10 +29,7 @@ class EditableChamp::EditableChampComponent < ApplicationComponent 'editable-champ': true, "editable-champ-#{@champ.type_champ}": true, "hidden": !@champ.visible?, - "fr-input-group": input_group.include?(@champ.type_champ), - "fr-select-group": select_group.include?(@champ.type_champ), - "fr-radio-group": radio_group.include?(@champ.type_champ), - "fr-fieldset": @champ.legend_label? + dsfr_group_classname => true }.merge(input_group_error_class_names) ), id: @champ.input_group_id, diff --git a/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml b/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml index 26c1178f4..2b254064a 100644 --- a/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml +++ b/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml @@ -1,6 +1,7 @@ -= content_tag((@champ.legend_label? ? :fieldset : :div), html_options) do += content_tag((@champ.dsfr_champ_container), html_options) do - if has_label?(@champ) = render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at + = render component_class.new(form: @form, champ: @champ, seen_at: @seen_at) = render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: errors_on_attribute?, error_full_messages: error_full_messages, described_by: describedby_id) diff --git a/app/models/champ.rb b/app/models/champ.rb index 1b01faa97..430bce321 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -156,6 +156,10 @@ class Champ < ApplicationRecord stable_id_with_maybe_row.split('|') end + def dsfr_champ_container + :div + end + def html_label? true end diff --git a/app/models/champs/checkbox_champ.rb b/app/models/champs/checkbox_champ.rb index 671015373..a683ce0d1 100644 --- a/app/models/champs/checkbox_champ.rb +++ b/app/models/champs/checkbox_champ.rb @@ -1,4 +1,8 @@ class Champs::CheckboxChamp < Champs::BooleanChamp + def dsfr_champ_container + :fieldset + end + def for_export true? ? 'on' : 'off' end @@ -7,9 +11,8 @@ class Champs::CheckboxChamp < Champs::BooleanChamp mandatory? && (blank? || !true?) end - # TODO remove when normalize_checkbox_values is over - def true? - value_with_legacy == TRUE_VALUE + def legend_label? + false end def html_label? @@ -19,11 +22,4 @@ class Champs::CheckboxChamp < Champs::BooleanChamp def single_checkbox? true end - - private - - # TODO remove when normalize_checkbox_values is over - def value_with_legacy - value == 'on' ? TRUE_VALUE : value - end end diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index 9872957aa..ec579c2a6 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -30,6 +30,10 @@ class Champs::DropDownListChamp < Champ render_as_radios? end + def dsfr_champ_container + render_as_radios? ? :fieldset : :div + end + def selected other? ? OTHER : value end diff --git a/app/models/champs/linked_drop_down_list_champ.rb b/app/models/champs/linked_drop_down_list_champ.rb index 461fb355d..50e85d8f4 100644 --- a/app/models/champs/linked_drop_down_list_champ.rb +++ b/app/models/champs/linked_drop_down_list_champ.rb @@ -13,6 +13,10 @@ class Champs::LinkedDropDownListChamp < Champ end end + def dsfr_champ_container + :fieldset + end + def secondary_value if value.present? JSON.parse(value)[1] diff --git a/app/models/champs/multiple_drop_down_list_champ.rb b/app/models/champs/multiple_drop_down_list_champ.rb index 00bf4a2fb..ebe3fa64f 100644 --- a/app/models/champs/multiple_drop_down_list_champ.rb +++ b/app/models/champs/multiple_drop_down_list_champ.rb @@ -43,10 +43,18 @@ class Champs::MultipleDropDownListChamp < Champ enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX end + def dsfr_champ_container + render_as_checkboxes? ? :fieldset : :div + end + def html_label? !render_as_checkboxes? end + def legend_label? + true + end + def single_checkbox? render_as_checkboxes? end diff --git a/app/models/champs/yes_no_champ.rb b/app/models/champs/yes_no_champ.rb index 3cdf6a1b0..59572bd4e 100644 --- a/app/models/champs/yes_no_champ.rb +++ b/app/models/champs/yes_no_champ.rb @@ -1,4 +1,8 @@ class Champs::YesNoChamp < Champs::BooleanChamp + def dsfr_champ_container + :fieldset + end + def legend_label? true end