fix(drop_down_list): fix other option with combobox and some cleanup
This commit is contained in:
parent
4a698f8264
commit
d76123831c
13 changed files with 25 additions and 48 deletions
|
@ -13,6 +13,6 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
|
|||
|
||||
def contains_long_option?
|
||||
max_length = 100
|
||||
@champ.options.any? { _1.size > max_length }
|
||||
@champ.enabled_non_empty_options.any? { _1.size > max_length }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
.fr-radio-group
|
||||
= @form.radio_button :value, Champs::DropDownListChamp::OTHER, checked: @champ.other?, id: "#{@champ.id}_radio_option_other"
|
||||
%label.fr-label{ for: "#{@champ.id}_radio_option_other" }
|
||||
Autre
|
||||
= t('shared.champs.drop_down_list.other')
|
||||
- elsif @champ.render_as_combobox?
|
||||
= render Dsfr::ComboboxComponent.new form: @form, name: :value, options: @champ.enabled_non_empty_options, selected: @champ.selected, id: @champ.input_id, class: select_class_names, describedby: @champ.describedby_id
|
||||
= render Dsfr::ComboboxComponent.new form: @form, name: :value, options: @champ.enabled_non_empty_options(other: true), selected: @champ.selected, id: @champ.input_id, class: select_class_names, describedby: @champ.describedby_id
|
||||
- else
|
||||
= @form.select :value,
|
||||
@champ.options.compact_blank,
|
||||
@champ.enabled_non_empty_options(other: true),
|
||||
{ selected: @champ.selected, include_blank: true },
|
||||
required: @champ.required?,
|
||||
id: @champ.input_id,
|
||||
|
|
|
@ -151,6 +151,8 @@ export class Combobox {
|
|||
this.#open = false;
|
||||
this.#focusedOption = null;
|
||||
this._render(Action.Close);
|
||||
} else {
|
||||
this._render(Action.Update);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +198,6 @@ export class Combobox {
|
|||
}
|
||||
|
||||
close() {
|
||||
if (!this.#open) return;
|
||||
this.#open = false;
|
||||
this.#focusedOption = null;
|
||||
if (!this.#allowsCustomValue && !this.#selectedOption) {
|
||||
|
@ -238,7 +239,7 @@ export class Combobox {
|
|||
return this.#options;
|
||||
}
|
||||
|
||||
return matchSorter(this.#options, this.#inputValue, { keys: ['value'] });
|
||||
return matchSorter(this.#options, this.#inputValue, { keys: ['label'] });
|
||||
}
|
||||
|
||||
private get _focusedOptionIndex(): number {
|
||||
|
|
|
@ -20,7 +20,6 @@ class Champ < ApplicationRecord
|
|||
:drop_down_list_options,
|
||||
:drop_down_other?,
|
||||
:drop_down_list_options?,
|
||||
:drop_down_list_disabled_options,
|
||||
:drop_down_list_enabled_non_empty_options,
|
||||
:drop_down_secondary_libelle,
|
||||
:drop_down_secondary_description,
|
||||
|
|
|
@ -19,14 +19,6 @@ class Champs::DropDownListChamp < Champ
|
|||
drop_down_list_options?
|
||||
end
|
||||
|
||||
def options
|
||||
if drop_down_other?
|
||||
drop_down_list_options + [["Autre", OTHER]]
|
||||
else
|
||||
drop_down_list_options
|
||||
end
|
||||
end
|
||||
|
||||
def html_label?
|
||||
!render_as_radios?
|
||||
end
|
||||
|
@ -39,16 +31,12 @@ class Champs::DropDownListChamp < Champ
|
|||
other? ? OTHER : value
|
||||
end
|
||||
|
||||
def disabled_options
|
||||
drop_down_list_disabled_options
|
||||
end
|
||||
|
||||
def enabled_non_empty_options
|
||||
drop_down_list_enabled_non_empty_options
|
||||
def enabled_non_empty_options(other: false)
|
||||
drop_down_list_enabled_non_empty_options(other:)
|
||||
end
|
||||
|
||||
def other?
|
||||
drop_down_other? && (other || (value.present? && drop_down_list_options.exclude?(value)))
|
||||
drop_down_other? && (other || (value.present? && enabled_non_empty_options.exclude?(value)))
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
|
|
|
@ -5,14 +5,6 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
drop_down_list_options?
|
||||
end
|
||||
|
||||
def options
|
||||
drop_down_list_options
|
||||
end
|
||||
|
||||
def disabled_options
|
||||
drop_down_list_disabled_options
|
||||
end
|
||||
|
||||
def enabled_non_empty_options
|
||||
drop_down_list_enabled_non_empty_options
|
||||
end
|
||||
|
|
|
@ -115,7 +115,7 @@ class GroupeInstructeur < ApplicationRecord
|
|||
when TypeDeChamp.type_champs.fetch(:regions)
|
||||
APIGeoService.regions.map { _1[:code] }
|
||||
when TypeDeChamp.type_champs.fetch(:drop_down_list)
|
||||
routing_tdc.options_with_drop_down_other
|
||||
routing_tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1.last : _1 }
|
||||
end
|
||||
routing_rule.right.value.in?(options)
|
||||
end
|
||||
|
|
|
@ -109,12 +109,7 @@ class Logic::ChampValue < Logic::Term
|
|||
when MANAGED_TYPE_DE_CHAMP.fetch(:regions)
|
||||
APIGeoService.regions.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
else
|
||||
opts = tdc.drop_down_list_enabled_non_empty_options.map { |option| [option, option] }
|
||||
if tdc.drop_down_other?
|
||||
opts + [["Autre", Champs::DropDownListChamp::OTHER]]
|
||||
else
|
||||
opts
|
||||
end
|
||||
tdc.drop_down_list_enabled_non_empty_options(other: true).map { _1.is_a?(Array) ? _1 : [_1, _1] }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -534,15 +534,13 @@ class TypeDeChamp < ApplicationRecord
|
|||
drop_down_list_options.filter { |v| (v =~ /^--.*--$/).present? }
|
||||
end
|
||||
|
||||
def drop_down_list_enabled_non_empty_options
|
||||
(drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?)
|
||||
end
|
||||
def drop_down_list_enabled_non_empty_options(other: false)
|
||||
list_options = (drop_down_list_options - drop_down_list_disabled_options).reject(&:empty?)
|
||||
|
||||
def options_with_drop_down_other
|
||||
if drop_down_other?
|
||||
drop_down_options + [Champs::DropDownListChamp::OTHER]
|
||||
if other && drop_down_other?
|
||||
list_options + [[I18n.t('shared.champs.drop_down_list.other'), Champs::DropDownListChamp::OTHER]]
|
||||
else
|
||||
drop_down_options
|
||||
list_options
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ def render_single_champ(pdf, champ)
|
|||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible')
|
||||
champ.options.compact_blank.each do |option|
|
||||
champ.enabled_non_empty_options.each do |option|
|
||||
format_with_checkbox(pdf, option)
|
||||
end
|
||||
pdf.text "\n"
|
||||
|
@ -162,7 +162,7 @@ def render_single_champ(pdf, champ)
|
|||
add_libelle(pdf, champ)
|
||||
add_optionnal_description(pdf, champ)
|
||||
add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles')
|
||||
champ.options.compact_blank.each do |option|
|
||||
champ.enabled_non_empty_options.each do |option|
|
||||
format_with_checkbox(pdf, option)
|
||||
end
|
||||
pdf.text "\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue