refactor(spinner): dependent-conditions on champ wrapper instead of each champ
This commit is contained in:
parent
26236a11ba
commit
5bff5542f1
13 changed files with 33 additions and 30 deletions
|
@ -534,6 +534,11 @@
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldset ~ .spinner {
|
||||||
|
position: relative;
|
||||||
|
top: -($default-fields-spacer / 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-react-component-value]:not([data-react-component-value^="ComboMultiple"]) {
|
[data-react-component-value]:not([data-react-component-value^="ComboMultiple"]) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
= @form.check_box :value,
|
= @form.check_box :value,
|
||||||
{ required: @champ.required?, id: @champ.input_id, checked: @champ.true?, aria: { describedby: @champ.describedby_id }, data: data_dependent_conditions },
|
{ required: @champ.required?, id: @champ.input_id, checked: @champ.true?, aria: { describedby: @champ.describedby_id } },
|
||||||
'true',
|
'true',
|
||||||
'false'
|
'false'
|
||||||
|
|
|
@ -3,5 +3,4 @@
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
step: :any,
|
step: :any,
|
||||||
placeholder: "3.14",
|
placeholder: "3.14",
|
||||||
required: @champ.required?,
|
required: @champ.required?
|
||||||
data: data_dependent_conditions
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- if @champ.options?
|
- if @champ.options?
|
||||||
- if @champ.render_as_radios?
|
- if @champ.render_as_radios?
|
||||||
%fieldset.radios{ data: data_dependent_conditions }
|
%fieldset.radios
|
||||||
- @champ.enabled_non_empty_options.each do |option|
|
- @champ.enabled_non_empty_options.each do |option|
|
||||||
%label
|
%label
|
||||||
= @form.radio_button :value, option
|
= @form.radio_button :value, option
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
= @form.radio_button :value, Champs::DropDownListChamp::OTHER, checked: @champ.other_value_present?
|
= @form.radio_button :value, Champs::DropDownListChamp::OTHER, checked: @champ.other_value_present?
|
||||||
Autre
|
Autre
|
||||||
- else
|
- else
|
||||||
= @form.select :value, @champ.options_without_empty_value_when_mandatory(@champ.options), { selected: @champ.selected }, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id }, data: data_dependent_conditions
|
= @form.select :value, @champ.options_without_empty_value_when_mandatory(@champ.options), { selected: @champ.selected }, required: @champ.mandatory?, id: @champ.input_id, aria: { describedby: @champ.describedby_id }
|
||||||
|
|
||||||
- if @champ.drop_down_other?
|
- if @champ.drop_down_other?
|
||||||
= render EditableChamp::DropDownOtherInputComponent.new(form: @form, champ: @champ)
|
= render EditableChamp::DropDownOtherInputComponent.new(form: @form, champ: @champ)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.drop_down_other{ class: @champ.other_value_present? ? '' : 'hidden' }
|
.drop_down_other{ class: @champ.other_value_present? ? '' : 'hidden' }
|
||||||
.notice
|
.notice
|
||||||
%p Veuillez saisir votre autre choix
|
%p Veuillez saisir votre autre choix
|
||||||
= @form.text_field :value_other, maxlength: 200, size: nil, disabled: !@champ.other_value_present?, data: data_dependent_conditions
|
= @form.text_field :value_other, maxlength: 200, size: nil, disabled: !@champ.other_value_present?
|
||||||
|
|
|
@ -2,8 +2,4 @@ class EditableChamp::EditableChampBaseComponent < ApplicationComponent
|
||||||
def initialize(form:, champ:, seen_at: nil)
|
def initialize(form:, champ:, seen_at: nil)
|
||||||
@form, @champ, @seen_at = form, champ, seen_at
|
@form, @champ, @seen_at = form, champ, seen_at
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_dependent_conditions
|
|
||||||
{ "dependent-conditions": "true" } if @champ.dependent_conditions?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
"hidden": !@champ.visible?
|
"hidden": !@champ.visible?
|
||||||
),
|
),
|
||||||
id: @champ.input_group_id,
|
id: @champ.input_group_id,
|
||||||
data: { controller: stimulus_controller }
|
data: { controller: stimulus_controller, **data_dependent_conditions }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,4 +45,12 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
controllers.join(' ')
|
controllers.join(' ')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def data_dependent_conditions
|
||||||
|
if @champ.dependent_conditions?
|
||||||
|
{ "dependent-conditions": "true" }
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,4 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: 5,
|
placeholder: 5,
|
||||||
required: @champ.required?,
|
required: @champ.required?
|
||||||
data: data_dependent_conditions
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- if @champ.options?
|
- if @champ.options?
|
||||||
- if @champ.render_as_checkboxes?
|
- if @champ.render_as_checkboxes?
|
||||||
= @form.collection_check_boxes(:value, @champ.enabled_non_empty_options, :to_s, :to_s, data: data_dependent_conditions) do |b|
|
= @form.collection_check_boxes(:value, @champ.enabled_non_empty_options, :to_s, :to_s) do |b|
|
||||||
- tag.div(class: 'editable-champ editable-champ-checkbox') do
|
- tag.div(class: 'editable-champ editable-champ-checkbox') do
|
||||||
- b.label do
|
- b.label do
|
||||||
- b.check_box({ multiple: true, checked: @champ&.selected_options&.include?(b.value), aria: { describedby: @champ.describedby_id } }) + b.text
|
- b.check_box({ multiple: true, checked: @champ&.selected_options&.include?(b.value), aria: { describedby: @champ.describedby_id } }) + b.text
|
||||||
|
|
|
@ -2,5 +2,4 @@
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id },
|
||||||
placeholder: @champ.libelle,
|
placeholder: @champ.libelle,
|
||||||
required: @champ.required?,
|
required: @champ.required?
|
||||||
data: data_dependent_conditions
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
= @form.text_field :value,
|
= @form.text_field :value,
|
||||||
id: @champ.input_id,
|
id: @champ.input_id,
|
||||||
required: @champ.required?,
|
required: @champ.required?,
|
||||||
aria: { describedby: @champ.describedby_id },
|
aria: { describedby: @champ.describedby_id }
|
||||||
data: data_dependent_conditions
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
%fieldset.radios{ data: data_dependent_conditions }
|
%fieldset.radios
|
||||||
%label
|
%label
|
||||||
= @form.radio_button :value, true
|
= @form.radio_button :value, true
|
||||||
Oui
|
Oui
|
||||||
|
|
|
@ -111,28 +111,26 @@ export class AutosaveController extends ApplicationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private showConditionnalSpinner(target: HTMLInputElement) {
|
private showConditionnalSpinner(target: HTMLInputElement) {
|
||||||
if (target.dataset.dependentConditions) {
|
const champWrapperElement = target.closest(
|
||||||
this.showSpinner(target);
|
'.editable-champ[data-dependent-conditions]'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!champWrapperElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for some champs, like checkbox, spinner is attached on fieldset
|
this.showSpinner(champWrapperElement);
|
||||||
const parentFieldset = target.closest('fieldset');
|
|
||||||
|
|
||||||
if (parentFieldset?.dataset?.dependentConditions) {
|
|
||||||
this.showSpinner(parentFieldset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private showSpinner(champElement: HTMLElement) {
|
private showSpinner(champElement: Element) {
|
||||||
this.#spinnerTimeoutId = setTimeout(() => {
|
this.#spinnerTimeoutId = setTimeout(() => {
|
||||||
// do not do anything if there is already a spinner for this champ, like SIRET champ
|
// do not do anything if there is already a spinner for this champ, like SIRET champ
|
||||||
if (!champElement.nextElementSibling?.classList.contains('spinner')) {
|
if (!champElement.querySelector('.spinner')) {
|
||||||
const spinner = document.createElement('div');
|
const spinner = document.createElement('div');
|
||||||
spinner.classList.add('spinner', 'spinner-removable');
|
spinner.classList.add('spinner', 'spinner-removable');
|
||||||
spinner.setAttribute('aria-live', 'live');
|
spinner.setAttribute('aria-live', 'live');
|
||||||
spinner.setAttribute('aria-label', 'Chargement en cours…');
|
spinner.setAttribute('aria-label', 'Chargement en cours…');
|
||||||
champElement.after(spinner);
|
champElement.appendChild(spinner);
|
||||||
}
|
}
|
||||||
}, AUTOSAVE_CONDITIONAL_SPINNER_DEBOUNCE_DELAY);
|
}, AUTOSAVE_CONDITIONAL_SPINNER_DEBOUNCE_DELAY);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue