remove enabled_non_empty_options indirection
This commit is contained in:
parent
8b5f689a67
commit
cfb03fc747
6 changed files with 14 additions and 22 deletions
|
@ -9,11 +9,11 @@ class Champs::DropDownListChamp < Champ
|
|||
validate :value_is_in_options, if: -> { !(value.blank? || drop_down_other?) && validate_champ_value_or_prefill? }
|
||||
|
||||
def render_as_radios?
|
||||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_RADIO
|
||||
drop_down_list_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
|
||||
drop_down_list_enabled_non_empty_options.size >= THRESHOLD_NB_OPTIONS_AS_AUTOCOMPLETE
|
||||
end
|
||||
|
||||
def html_label?
|
||||
|
@ -28,12 +28,8 @@ class Champs::DropDownListChamp < Champ
|
|||
other? ? OTHER : value
|
||||
end
|
||||
|
||||
def enabled_non_empty_options(other: false)
|
||||
drop_down_list_enabled_non_empty_options(other:)
|
||||
end
|
||||
|
||||
def other?
|
||||
drop_down_other? && (other || (value.present? && enabled_non_empty_options.exclude?(value)))
|
||||
drop_down_other? && (other || (value.present? && drop_down_list_enabled_non_empty_options.exclude?(value)))
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
|
@ -71,7 +67,7 @@ class Champs::DropDownListChamp < Champ
|
|||
private
|
||||
|
||||
def value_is_in_options
|
||||
return if enabled_non_empty_options.include?(value)
|
||||
return if drop_down_list_enabled_non_empty_options.include?(value)
|
||||
|
||||
errors.add(:value, :not_in_options)
|
||||
end
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
class Champs::MultipleDropDownListChamp < Champ
|
||||
validate :values_are_in_options, if: -> { value.present? && validate_champ_value_or_prefill? }
|
||||
|
||||
def enabled_non_empty_options
|
||||
drop_down_list_enabled_non_empty_options
|
||||
end
|
||||
|
||||
THRESHOLD_NB_OPTIONS_AS_CHECKBOX = 5
|
||||
|
||||
def search_terms
|
||||
|
@ -18,7 +14,7 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
end
|
||||
|
||||
def render_as_checkboxes?
|
||||
enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
||||
drop_down_list_enabled_non_empty_options.size <= THRESHOLD_NB_OPTIONS_AS_CHECKBOX
|
||||
end
|
||||
|
||||
def html_label?
|
||||
|
@ -51,7 +47,7 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
end
|
||||
|
||||
def focusable_input_id
|
||||
render_as_checkboxes? ? checkbox_id(enabled_non_empty_options.first) : input_id
|
||||
render_as_checkboxes? ? checkbox_id(drop_down_list_enabled_non_empty_options.first) : input_id
|
||||
end
|
||||
|
||||
def checkbox_id(value)
|
||||
|
@ -67,7 +63,7 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
end
|
||||
|
||||
def unselected_options
|
||||
enabled_non_empty_options - selected_options
|
||||
drop_down_list_enabled_non_empty_options - selected_options
|
||||
end
|
||||
|
||||
def value=(value)
|
||||
|
@ -97,7 +93,7 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
def values_are_in_options
|
||||
json = selected_options.compact_blank
|
||||
return if json.empty?
|
||||
return if (json - enabled_non_empty_options).empty?
|
||||
return if (json - drop_down_list_enabled_non_empty_options).empty?
|
||||
|
||||
errors.add(:value, :not_in_options)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue