From 37796b8843621d9030d553c1491f7a686a3413ea Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Mon, 10 Jul 2023 14:48:33 +0200 Subject: [PATCH] Checkbox au DSFR --- app/assets/stylesheets/forms.scss | 1 - .../champ_label_component.html.haml | 4 ++-- .../checkbox_component/checkbox_component.html.haml | 12 ++++++++---- app/models/champ.rb | 4 ++++ app/models/champs/checkbox_champ.rb | 8 ++++++++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss index 448576932..372d8f196 100644 --- a/app/assets/stylesheets/forms.scss +++ b/app/assets/stylesheets/forms.scss @@ -125,7 +125,6 @@ &.editable-champ-checkbox { label { - padding-left: 28px; font-weight: normal; } diff --git a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml index 52afe69e9..daf49d3b9 100644 --- a/app/components/editable_champ/champ_label_component/champ_label_component.html.haml +++ b/app/components/editable_champ/champ_label_component/champ_label_component.html.haml @@ -5,8 +5,8 @@ - render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - elsif @champ.legend_label? %legend.fr-fieldset__legend.fr-text--regular= render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at +- elsif @champ.single_checkbox? + -# no label to add - else .fr-label.mb-4{ id: @champ.labelledby_id } = render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at - - diff --git a/app/components/editable_champ/checkbox_component/checkbox_component.html.haml b/app/components/editable_champ/checkbox_component/checkbox_component.html.haml index 34e6a0a5a..5bc156725 100644 --- a/app/components/editable_champ/checkbox_component/checkbox_component.html.haml +++ b/app/components/editable_champ/checkbox_component/checkbox_component.html.haml @@ -1,4 +1,8 @@ -= @form.check_box :value, - { required: @champ.required?, id: @champ.input_id, checked: @champ.true?, aria: { describedby: @champ.describedby_id }, class: class_names('required' => @champ.required?)}, - 'true', - 'false' +.fr-fieldset__element + .fr-checkbox-group + = @form.check_box :value, + { required: @champ.required?, id: @champ.input_id, checked: @champ.true?, aria: { describedby: @champ.describedby_id }, class: class_names('required' => @champ.required?)}, + 'true', + 'false' + %label.fr-label{ for: @champ.input_id } + = render EditableChamp::ChampLabelContentComponent.new form: @form, champ: @champ, seen_at: @seen_at diff --git a/app/models/champ.rb b/app/models/champ.rb index f8dc56ff9..1b01faa97 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -164,6 +164,10 @@ class Champ < ApplicationRecord false end + def single_checkbox? + false + end + def input_group_id "champ-#{html_id}" end diff --git a/app/models/champs/checkbox_champ.rb b/app/models/champs/checkbox_champ.rb index dd67f7be0..671015373 100644 --- a/app/models/champs/checkbox_champ.rb +++ b/app/models/champs/checkbox_champ.rb @@ -12,6 +12,14 @@ class Champs::CheckboxChamp < Champs::BooleanChamp value_with_legacy == TRUE_VALUE end + def html_label? + false + end + + def single_checkbox? + true + end + private # TODO remove when normalize_checkbox_values is over