demarches-normaliennes/app/models/drop_down_list.rb

25 lines
638 B
Ruby
Raw Normal View History

2018-03-06 13:44:29 +01:00
class DropDownList < ApplicationRecord
2016-08-09 16:21:39 +02:00
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
2018-01-11 19:08:04 +01:00
options.select{ |v| (v =~ /^--.*--$/).present? }
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'
2016-08-09 16:21:39 +02:00
end
end