diff --git a/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml b/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml index 7fcd2ff35..7e867fa5c 100644 --- a/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml +++ b/app/components/editable_champ/drop_down_list_component/drop_down_list_component.html.haml @@ -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, diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index 9872957aa..ee9c5b9c3 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -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