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
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_group_error_class_names
|
def fr_select?
|
||||||
if @champ && @champ.legend_label?
|
return false if fr_fieldset?
|
||||||
{
|
|
||||||
"fr-fieldset--error": errors_on_attribute?,
|
[
|
||||||
"fr-fieldset--valid": !errors_on_attribute? && errors_on_another_attribute?
|
'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
|
else
|
||||||
{
|
"#{dsfr_input_classname}-group"
|
||||||
"fr-input-group--error": errors_on_attribute?,
|
|
||||||
"fr-input-group--valid": !errors_on_attribute? && errors_on_another_attribute?
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
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
|
def input_error_class_names
|
||||||
{ 'fr-input--error': errors_on_attribute? }
|
{
|
||||||
|
"#{dsfr_input_classname}--error": errors_on_attribute?
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_error_opts
|
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|
|
- @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
|
.fr-fieldset__element.fr-mb-0
|
||||||
- if commune_options.empty?
|
- if commune_options.empty?
|
||||||
- #noop
|
- # noop
|
||||||
- elsif commune_options.size <= 3
|
- elsif commune_options.size <= 3
|
||||||
%fieldset.fr-fieldset
|
%fieldset.fr-fieldset
|
||||||
.fr-fieldset__legend--regular.fr-fieldset__legend= t('.commune').html_safe
|
.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
|
"EditableChamp::#{@champ.type_champ.camelcase}Component".constantize
|
||||||
end
|
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
|
def html_options
|
||||||
{
|
{
|
||||||
class: class_names(
|
class: class_names(
|
||||||
|
@ -70,10 +29,7 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
'editable-champ': true,
|
'editable-champ': true,
|
||||||
"editable-champ-#{@champ.type_champ}": true,
|
"editable-champ-#{@champ.type_champ}": true,
|
||||||
"hidden": !@champ.visible?,
|
"hidden": !@champ.visible?,
|
||||||
"fr-input-group": input_group.include?(@champ.type_champ),
|
dsfr_group_classname => true
|
||||||
"fr-select-group": select_group.include?(@champ.type_champ),
|
|
||||||
"fr-radio-group": radio_group.include?(@champ.type_champ),
|
|
||||||
"fr-fieldset": @champ.legend_label?
|
|
||||||
}.merge(input_group_error_class_names)
|
}.merge(input_group_error_class_names)
|
||||||
),
|
),
|
||||||
id: @champ.input_group_id,
|
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)
|
- if has_label?(@champ)
|
||||||
= render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at
|
= 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 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)
|
= 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('|')
|
stable_id_with_maybe_row.split('|')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dsfr_champ_container
|
||||||
|
:div
|
||||||
|
end
|
||||||
|
|
||||||
def html_label?
|
def html_label?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
class Champs::CheckboxChamp < Champs::BooleanChamp
|
class Champs::CheckboxChamp < Champs::BooleanChamp
|
||||||
|
def dsfr_champ_container
|
||||||
|
:fieldset
|
||||||
|
end
|
||||||
|
|
||||||
def for_export
|
def for_export
|
||||||
true? ? 'on' : 'off'
|
true? ? 'on' : 'off'
|
||||||
end
|
end
|
||||||
|
@ -7,9 +11,8 @@ class Champs::CheckboxChamp < Champs::BooleanChamp
|
||||||
mandatory? && (blank? || !true?)
|
mandatory? && (blank? || !true?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO remove when normalize_checkbox_values is over
|
def legend_label?
|
||||||
def true?
|
false
|
||||||
value_with_legacy == TRUE_VALUE
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_label?
|
def html_label?
|
||||||
|
@ -19,11 +22,4 @@ class Champs::CheckboxChamp < Champs::BooleanChamp
|
||||||
def single_checkbox?
|
def single_checkbox?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# TODO remove when normalize_checkbox_values is over
|
|
||||||
def value_with_legacy
|
|
||||||
value == 'on' ? TRUE_VALUE : value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,6 +30,10 @@ class Champs::DropDownListChamp < Champ
|
||||||
render_as_radios?
|
render_as_radios?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dsfr_champ_container
|
||||||
|
render_as_radios? ? :fieldset : :div
|
||||||
|
end
|
||||||
|
|
||||||
def selected
|
def selected
|
||||||
other? ? OTHER : value
|
other? ? OTHER : value
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,10 @@ class Champs::LinkedDropDownListChamp < Champ
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dsfr_champ_container
|
||||||
|
:fieldset
|
||||||
|
end
|
||||||
|
|
||||||
def secondary_value
|
def secondary_value
|
||||||
if value.present?
|
if value.present?
|
||||||
JSON.parse(value)[1]
|
JSON.parse(value)[1]
|
||||||
|
|
|
@ -43,10 +43,18 @@ class Champs::MultipleDropDownListChamp < Champ
|
||||||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dsfr_champ_container
|
||||||
|
render_as_checkboxes? ? :fieldset : :div
|
||||||
|
end
|
||||||
|
|
||||||
def html_label?
|
def html_label?
|
||||||
!render_as_checkboxes?
|
!render_as_checkboxes?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def legend_label?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def single_checkbox?
|
def single_checkbox?
|
||||||
render_as_checkboxes?
|
render_as_checkboxes?
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
class Champs::YesNoChamp < Champs::BooleanChamp
|
class Champs::YesNoChamp < Champs::BooleanChamp
|
||||||
|
def dsfr_champ_container
|
||||||
|
:fieldset
|
||||||
|
end
|
||||||
|
|
||||||
def legend_label?
|
def legend_label?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue