fix(Champs::DossierLinkChamp): when required, should point to existing dossier

This commit is contained in:
mfo 2024-09-06 11:05:21 +02:00
parent 9fd53b182a
commit eb8b9a13ca
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
5 changed files with 54 additions and 6 deletions

View file

@ -2,9 +2,16 @@
class Champs::DossierLinkChamp < Champ
validate :value_integerable, if: -> { value.present? }, on: :prefill
validate :dossier_exists, if: -> { validate_champ_value? && !value.nil? }
private
def dossier_exists
if mandatory? && !Dossier.exists?(value)
errors.add(:value, :not_found)
end
end
def value_integerable
Integer(value)
rescue ArgumentError