fix(Champs::PhoneChamp): validates Champs::PhoneChamp respecting it's validation context.

This commit is contained in:
mfo 2024-04-01 07:16:32 +02:00
parent 374d763084
commit d7f152f4af
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 37 additions and 35 deletions

View file

@ -25,7 +25,8 @@ class Champs::PhoneChamp < Champs::TextChamp
possible: true,
allow_blank: true,
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
}, unless: -> { Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES) }
},
if: -> { (validate_champ_value? || validation_context == :prefill) && !Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES) }
def to_s
return '' if value.blank?