[#2258] Let dynamic type validate the type de champ
This commit is contained in:
parent
695426316c
commit
3fea14c07d
3 changed files with 34 additions and 0 deletions
|
@ -59,6 +59,17 @@ class TypeDeChamp < ApplicationRecord
|
|||
before_validation :check_mandatory
|
||||
before_save :remove_piece_justificative_template, if: -> { type_champ_changed? }
|
||||
|
||||
def valid?(context = nil)
|
||||
super
|
||||
if dynamic_type.present?
|
||||
dynamic_type.valid?
|
||||
errors.merge!(dynamic_type.errors)
|
||||
end
|
||||
errors.empty?
|
||||
end
|
||||
|
||||
alias_method :validate, :valid?
|
||||
|
||||
def set_dynamic_type
|
||||
@dynamic_type = type_champ.present? ? self.class.type_champ_to_class_name(type_champ).constantize.new(self) : nil
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class TypesDeChamp::TypeDeChampBase
|
||||
include ActiveModel::Validations
|
||||
|
||||
def initialize(type_de_champ)
|
||||
@type_de_champ = type_de_champ
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue