demarches-normaliennes/app/models/drop_down_list.rb
2019-01-03 12:08:25 +01:00

20 lines
530 B
Ruby

class DropDownList < ApplicationRecord
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 =~ /^--.*--$/).present? }
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 == TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
end
end