validate values inclusion

This commit is contained in:
sebastiencarceles 2023-01-24 15:10:25 +01:00
parent d648ac31c2
commit d5ffd61ab6
9 changed files with 64 additions and 7 deletions

View file

@ -23,6 +23,8 @@
class Champs::MultipleDropDownListChamp < Champ
before_save :format_before_save
validate :values_are_in_options, if: -> { value.present? }
def options?
drop_down_list_options?
end
@ -90,4 +92,11 @@ class Champs::MultipleDropDownListChamp < Champ
end
end
end
def values_are_in_options
return if (json = JSON.parse(value) - ['']).empty?
return if json.filter { |val| enabled_non_empty_options.exclude?(val) }.empty?
errors.add(:value, :not_in_options)
end
end

View file

@ -42,6 +42,7 @@ class PrefillParams
TypeDeChamp.type_champs.fetch(:pays),
TypeDeChamp.type_champs.fetch(:regions),
TypeDeChamp.type_champs.fetch(:departements),
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
TypeDeChamp.type_champs.fetch(:epci)
]