extract rendering condition

This commit is contained in:
clemkeirua 2020-06-24 12:18:46 +02:00
parent 465449e684
commit 6b3631dbfe
4 changed files with 25 additions and 18 deletions

View file

@ -1,3 +1,7 @@
class Champs::DropDownListChamp < Champ
THRESHOLD_NB_OPTIONS_AS_RADIO = 5
def render_as_radios?
drop_down_list.enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO
end
end

View file

@ -23,6 +23,10 @@ class Champs::MultipleDropDownListChamp < Champ
value.present? ? selected_options.join(', ') : nil
end
def render_as_checkboxes?
drop_down_list.enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
end
private
def format_before_save