Merge pull request #10757 from mfo/US/fix-required-dossier-link-with-missing-dossier
correct: ETQ administrateur, je souhaite que les types de champ liens vers un dossier pointent vers un dossier valide si ils sont obligatoire
This commit is contained in:
commit
977e47fa74
5 changed files with 54 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue