amelioration(form): utilise les bonnes classes DSFR pour divers composants
This commit is contained in:
parent
2c04be5289
commit
f54ab0bf96
11 changed files with 103 additions and 70 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
class Champs::YesNoChamp < Champs::BooleanChamp
|
||||
def dsfr_champ_container
|
||||
:fieldset
|
||||
end
|
||||
|
||||
def legend_label?
|
||||
true
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue