demarches-normaliennes/app/models/drop_down_list.rb
2017-09-06 11:11:29 +02:00

24 lines
636 B
Ruby

class DropDownList < ActiveRecord::Base
belongs_to :type_de_champ
def options
result = value.split(/[\r\n]|[\r]|[\n]|[\n\r]/).reject(&:empty?)
result.blank? ? [] : [''] + result
end
def disabled_options
options.select{ |v| !(v =~ /^--.*--$/).nil? }
end
def selected_options(champ)
champ.object.value.blank? ? [] : multiple ? JSON.parse(champ.object.value) : [champ.object.value]
end
def selected_options_without_decorator(champ)
champ.value.blank? ? [] : multiple ? JSON.parse(champ.value) : [champ.value]
end
def multiple
type_de_champ.type_champ == 'multiple_drop_down_list'
end
end