demarches-normaliennes/app/models/concerns/champs_validate_concern.rb
simon lehericey 10a1ae5534
Revert "Merge pull request #10771 from tchak/refactor-champs-revert"
This reverts commit c902061ebf, reversing
changes made to b4ed11c788.
2024-09-19 11:09:01 +02:00

31 lines
658 B
Ruby

# frozen_string_literal: true
module ChampsValidateConcern
extend ActiveSupport::Concern
included do
protected
# Champs public/private must be validated depending on the context
def valid_champ_value?
valid?(public? ? :champs_public_value : :champs_private_value)
end
private
def validate_champ_value?
case validation_context
when :champs_public_value
public? && visible?
when :champs_private_value
private? && visible?
else
false
end
end
def validate_champ_value_or_prefill?
validate_champ_value? || validation_context == :prefill
end
end
end