2016-08-09 16:21:39 +02:00
|
|
|
class DropDownList < ActiveRecord::Base
|
|
|
|
belongs_to :type_de_champ
|
|
|
|
|
|
|
|
def options
|
2017-03-15 17:47:26 +01:00
|
|
|
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? }
|
2017-03-15 17:47:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def selected_options(champ)
|
2017-03-15 18:32:20 +01:00
|
|
|
champ.object.value.blank? ? [] : multiple ? JSON.parse(champ.object.value) : [champ.object.value]
|
2017-03-15 17:47:26 +01:00
|
|
|
end
|
|
|
|
|
2017-07-25 14:33:03 +02:00
|
|
|
def selected_options_without_decorator(champ)
|
|
|
|
champ.value.blank? ? [] : multiple ? JSON.parse(champ.value) : [champ.value]
|
|
|
|
end
|
|
|
|
|
2017-03-15 17:47:26 +01:00
|
|
|
def multiple
|
|
|
|
type_de_champ.type_champ == 'multiple_drop_down_list'
|
2016-08-09 16:21:39 +02:00
|
|
|
end
|
|
|
|
end
|