2018-03-06 13:44:29 +01:00
|
|
|
class DropDownList < ApplicationRecord
|
2016-08-09 16:21:39 +02:00
|
|
|
belongs_to :type_de_champ
|
|
|
|
|
2018-11-14 16:24:34 +01:00
|
|
|
before_validation :clean_value
|
|
|
|
|
2016-08-09 16:21:39 +02:00
|
|
|
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
|
2019-09-12 11:26:22 +02:00
|
|
|
options.filter { |v| (v =~ /^--.*--$/).present? }
|
2017-03-15 17:47:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def multiple
|
2018-08-28 16:22:34 +02:00
|
|
|
type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
|
2016-08-09 16:21:39 +02:00
|
|
|
end
|
2018-11-14 16:24:34 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clean_value
|
|
|
|
value = read_attribute(:value)
|
|
|
|
value = value ? value.split("\r\n").map(&:strip).join("\r\n") : ''
|
|
|
|
write_attribute(:value, value)
|
|
|
|
end
|
2016-08-09 16:21:39 +02:00
|
|
|
end
|