feat(combobox): use ComboboxComponent on drop_down_list champs
This commit is contained in:
parent
85024174d4
commit
fb917a221d
2 changed files with 7 additions and 0 deletions
|
@ -18,6 +18,8 @@
|
|||
= @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
|
||||
- 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
|
||||
- else
|
||||
= @form.select :value,
|
||||
@champ.options.compact_blank,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Champs::DropDownListChamp < Champ
|
||||
store_accessor :value_json, :other
|
||||
THRESHOLD_NB_OPTIONS_AS_RADIO = 5
|
||||
THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE = 20
|
||||
OTHER = '__other__'
|
||||
delegate :options_without_empty_value_when_mandatory, to: :type_de_champ
|
||||
|
||||
|
@ -10,6 +11,10 @@ class Champs::DropDownListChamp < Champ
|
|||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO
|
||||
end
|
||||
|
||||
def render_as_combobox?
|
||||
enabled_non_empty_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE
|
||||
end
|
||||
|
||||
def options?
|
||||
drop_down_list_options?
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue