display small selects as radio buttons
This commit is contained in:
parent
debbb21440
commit
22fc4c4195
3 changed files with 19 additions and 4 deletions
|
@ -1,2 +1,3 @@
|
||||||
class Champs::DropDownListChamp < Champ
|
class Champs::DropDownListChamp < Champ
|
||||||
|
THRESHOLD_NB_OPTIONS_AS_RADIO = 3
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,10 @@ class DropDownList < ApplicationRecord
|
||||||
result.blank? ? [] : [''] + result
|
result.blank? ? [] : [''] + result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enabled_non_empty_options
|
||||||
|
(options - disabled_options).reject(&:empty?)
|
||||||
|
end
|
||||||
|
|
||||||
def disabled_options
|
def disabled_options
|
||||||
options.filter { |v| (v =~ /^--.*--$/).present? }
|
options.filter { |v| (v =~ /^--.*--$/).present? }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +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::DropDownListChamp::THRESHOLD_NB_OPTIONS_AS_RADIO
|
||||||
disabled: champ.drop_down_list.disabled_options,
|
= form.select :value,
|
||||||
required: champ.mandatory?
|
champ.drop_down_list.options,
|
||||||
|
disabled: champ.drop_down_list.disabled_options,
|
||||||
|
required: champ.mandatory?
|
||||||
|
- else
|
||||||
|
%fieldset.radios
|
||||||
|
%legend.mandatory-explanation
|
||||||
|
Sélectionnez une des valeurs
|
||||||
|
- enabled_non_empty_options.each do |option|
|
||||||
|
%label
|
||||||
|
= form.radio_button :value, option
|
||||||
|
= option
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue