Move #selected_options to the only relevant model
This commit is contained in:
parent
c4b9a0b79e
commit
2e6c91e9b0
3 changed files with 8 additions and 8 deletions
|
@ -2,7 +2,11 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
before_save :format_before_save
|
||||
|
||||
def search_terms
|
||||
drop_down_list.selected_options(self)
|
||||
selected_options
|
||||
end
|
||||
|
||||
def selected_options
|
||||
value.blank? ? [] : JSON.parse(value)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -20,10 +24,10 @@ class Champs::MultipleDropDownListChamp < Champ
|
|||
end
|
||||
|
||||
def string_value
|
||||
drop_down_list.selected_options(self).join(', ')
|
||||
selected_options.join(', ')
|
||||
end
|
||||
|
||||
def value_for_export
|
||||
drop_down_list.selected_options(self).join(', ')
|
||||
selected_options.join(', ')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,10 +10,6 @@ class DropDownList < ApplicationRecord
|
|||
options.select { |v| (v =~ /^--.*--$/).present? }
|
||||
end
|
||||
|
||||
def selected_options(champ)
|
||||
champ.value.blank? ? [] : multiple ? JSON.parse(champ.value) : [champ.value]
|
||||
end
|
||||
|
||||
def multiple
|
||||
type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
- if champ.drop_down_list && champ.drop_down_list.options.any?
|
||||
= form.select :value,
|
||||
champ.drop_down_list.options,
|
||||
{ selected: champ.drop_down_list.selected_options(champ),
|
||||
{ selected: champ.selected_options,
|
||||
disabled: champ.drop_down_list.disabled_options },
|
||||
multiple: true,
|
||||
class: 'select2'
|
||||
|
|
Loading…
Reference in a new issue