display small multiple selects as checkboxes
This commit is contained in:
parent
22fc4c4195
commit
342129c893
2 changed files with 16 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
||||||
class Champs::MultipleDropDownListChamp < Champ
|
class Champs::MultipleDropDownListChamp < Champ
|
||||||
before_save :format_before_save
|
before_save :format_before_save
|
||||||
|
|
||||||
|
THRESHOLD_NB_OPTIONS_AS_RADIO = 3
|
||||||
|
|
||||||
def search_terms
|
def search_terms
|
||||||
selected_options
|
selected_options
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
- if champ.drop_down_list && champ.drop_down_list.options.any?
|
- if champ.drop_down_list && champ.drop_down_list.options.any?
|
||||||
= form.select :value,
|
- enabled_non_empty_options = champ.drop_down_list.enabled_non_empty_options
|
||||||
champ.drop_down_list.options,
|
- if enabled_non_empty_options.size > Champs::MultipleDropDownListChamp::THRESHOLD_NB_OPTIONS_AS_RADIO
|
||||||
{ selected: champ.selected_options,
|
= form.select :value,
|
||||||
disabled: champ.drop_down_list.disabled_options },
|
champ.drop_down_list.options,
|
||||||
multiple: true,
|
{ selected: champ.selected_options,
|
||||||
class: 'select2'
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue