Skip to content

Commit 614254c

Browse files
committed
Fix #124, error when arguments of PhoneNumber are falsy values
1 parent f8a85ce commit 614254c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/components/vue-tel-input.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,18 @@ export default {
482482
};
483483
},
484484
choose(country) {
485-
this.activeCountry = country;
486-
if (this.inputOptions && this.inputOptions.showDialCode && country) {
487-
this.phone = `+${country.dialCode}`;
488-
}
489-
if (this.phone && this.phone[0] === '+') {
485+
this.activeCountry = country || this.activeCountry || {};
486+
487+
if (this.phone
488+
&& this.phone[0] === '+'
489+
&& this.activeCountry.iso2
490+
&& this.phoneObject.number.national) {
491+
// Attach the current phone number with the newly selected country
490492
this.phone = PhoneNumber(this.phoneObject.number.national, this.activeCountry.iso2)
491493
.getNumber('international');
494+
} else if (this.inputOptions && this.inputOptions.showDialCode && country) {
495+
// Reset phone if the showDialCode is set
496+
this.phone = `+${country.dialCode}`;
492497
}
493498
this.$emit('input', this.phoneObject.number[this.parsedMode], this.phoneObject);
494499
this.$emit('onInput', this.phoneObject); // Deprecated

0 commit comments

Comments
 (0)