Merge pull request #6267 from tchak/format-phone-number

format phone numbers
This commit is contained in:
Paul Chavard 2021-06-15 09:22:45 +02:00 committed by GitHub
commit 139385bde3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -24,4 +24,8 @@ class Champs::PhoneChamp < Champs::TextChamp
allow_blank: true,
message: I18n.t(:not_a_phone, scope: 'activerecord.errors.messages')
}, unless: -> { Phonelib.valid_for_country?(value, :pf) }
def to_s
value.present? ? Phonelib.parse(value).full_national : ''
end
end

View file

@ -328,7 +328,7 @@ describe Champ do
context 'for phone champ' do
let(:type_de_champ) { build(:type_de_champ_phone) }
let(:value) { "0606060606" }
let(:value) { "06 06 06 06 06" }
it { is_expected.to eq([value]) }
end