replace html labels with h2 elements

Some elements should not be html labels, for example when they include sub-elements that contain labels (ex: a radio button that has a label on its own). Those are replaced with title elements
This commit is contained in:
clemkeirua 2020-03-05 16:57:08 +01:00 committed by GitHub Action
parent 62591623f4
commit 1a58dd69c2
4 changed files with 26 additions and 8 deletions

View file

@ -373,6 +373,12 @@
margin-bottom: $default-padding;
}
.label-not-label {
font-weight: bold;
font-size: 18px;
margin-bottom: $default-padding;
}
.explication {
margin-bottom: $default-fields-spacer;
padding: $default-padding / 2;

View file

@ -4,6 +4,12 @@ module ChampHelper
!types_without_label.include?(champ.type_champ)
end
def has_html_label?(champ)
types_with_no_html_label = [TypeDeChamp.type_champs.fetch(:civilite), TypeDeChamp.type_champs.fetch(:yes_no), TypeDeChamp.type_champs.fetch(:datetime), TypeDeChamp.type_champs.fetch(:piece_justificative)
]
types_with_no_html_label.include?(champ.type_champ)
end
def geo_data(champ)
# rubocop:disable Rails/OutputSafety
raw(champ.to_render_data.to_json)

View file

@ -1,11 +1,10 @@
= form.label champ.main_value_name do
#{champ.libelle}
- if champ.mandatory?
%span.mandatory *
- if champ.updated_at.present? && seen_at.present?
%span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) }
= "modifié le #{try_format_datetime(champ.updated_at)}"
= # we do this trick because some html elements should use 'label' and some should be plain paragraphs
- if has_html_label?(champ)
%h2.label-not-label
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
- else
= form.label champ.main_value_name do
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
- if champ.description.present?
.notice{ id: describedby_id(champ) }= string_to_html(champ.description)

View file

@ -0,0 +1,7 @@
#{champ.libelle}
- if champ.mandatory?
%span.mandatory *
- if champ.updated_at.present? && seen_at.present?
%span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) }
= "modifié le #{try_format_datetime(champ.updated_at)}"