From 342129c8939fec2dde3af98eebe8bfb563f3f762 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Wed, 17 Jun 2020 11:14:27 +0200 Subject: [PATCH] display small multiple selects as checkboxes --- .../champs/multiple_drop_down_list_champ.rb | 2 ++ .../_multiple_drop_down_list.html.haml | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/models/champs/multiple_drop_down_list_champ.rb b/app/models/champs/multiple_drop_down_list_champ.rb index ff120ac23..efd695631 100644 --- a/app/models/champs/multiple_drop_down_list_champ.rb +++ b/app/models/champs/multiple_drop_down_list_champ.rb @@ -1,6 +1,8 @@ class Champs::MultipleDropDownListChamp < Champ before_save :format_before_save + THRESHOLD_NB_OPTIONS_AS_RADIO = 3 + def search_terms selected_options end diff --git a/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml b/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml index efbb7dda2..56000873d 100644 --- a/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml +++ b/app/views/shared/dossiers/editable_champs/_multiple_drop_down_list.html.haml @@ -1,7 +1,15 @@ - if champ.drop_down_list && champ.drop_down_list.options.any? - = form.select :value, - champ.drop_down_list.options, - { selected: champ.selected_options, - disabled: champ.drop_down_list.disabled_options }, - multiple: true, - class: 'select2' + - enabled_non_empty_options = champ.drop_down_list.enabled_non_empty_options + - if enabled_non_empty_options.size > Champs::MultipleDropDownListChamp::THRESHOLD_NB_OPTIONS_AS_RADIO + = form.select :value, + champ.drop_down_list.options, + { selected: champ.selected_options, + disabled: champ.drop_down_list.disabled_options }, + multiple: true, + class: 'select2' + - else + - enabled_non_empty_options.each do |option| + .editable-champ.editable-champ-checkbox + %label + = form.check_box :value, { multiple: true, checked: champ&.value&.include?(option) }, option, nil + = option