-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: country prefill bug #299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,9 @@ export default { | |
} | ||
} | ||
}, | ||
compVal(newVal, oldVal){ | ||
this.initState() | ||
}, | ||
selectedCountryCode (newVal, oldVal) { | ||
if (this.compVal && newVal && oldVal) { | ||
this.compVal = this.compVal.replace(oldVal.code + oldVal.dial_code, newVal.code + newVal.dial_code) | ||
|
@@ -102,17 +105,7 @@ export default { | |
|
||
mounted () { | ||
if (this.compVal) { | ||
if (!this.compVal.startsWith('+')) { | ||
this.selectedCountryCode = this.getCountryBy(this.compVal.substring(2, 0)) | ||
} | ||
|
||
const phoneObj = parsePhoneNumber(this.compVal) | ||
if (phoneObj !== undefined && phoneObj) { | ||
if (!this.selectedCountryCode && phoneObj.country !== undefined && phoneObj.country) { | ||
this.selectedCountryCode = this.getCountryBy(phoneObj.country) | ||
} | ||
this.inputVal = phoneObj.nationalNumber | ||
} | ||
this.initState() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Ensure that the component's initialization logic in |
||
} | ||
if (!this.selectedCountryCode) { | ||
this.selectedCountryCode = this.getCountryBy() | ||
|
@@ -131,6 +124,7 @@ export default { | |
}, | ||
onInput (event) { | ||
this.inputVal = event?.target?.value.replace(/[^0-9]/g, '') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider allowing the plus sign ( |
||
}, | ||
onChangeCountryCode () { | ||
if (!this.selectedCountryCode && this.countries.length > 0) { | ||
|
@@ -139,6 +133,22 @@ export default { | |
if (this.canOnlyCountry && (this.inputVal === null || this.inputVal === '' || !this.inputVal)) { | ||
this.compVal = this.selectedCountryCode.code + this.selectedCountryCode.dial_code | ||
} | ||
}, | ||
initState() { | ||
if(this.compVal === null){ | ||
return; | ||
} | ||
if (!this.compVal.startsWith('+')) { | ||
this.selectedCountryCode = this.getCountryBy(this.compVal.substring(2, 0)) | ||
} | ||
|
||
const phoneObj = parsePhoneNumber(this.compVal) | ||
if (phoneObj !== undefined && phoneObj) { | ||
if (!this.selectedCountryCode && phoneObj.country !== undefined && phoneObj.country) { | ||
this.selectedCountryCode = this.getCountryBy(phoneObj.country) | ||
} | ||
this.inputVal = phoneObj.nationalNumber | ||
} | ||
Comment on lines
+137
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
compVal
method is designed to handle changes in the component's value but currently only callsthis.initState()
without actually comparingnewVal
andoldVal
or handling them in any specific way. This might not align with the PR objectives that suggestcompVal
should effectively deal with new and old values to ensure the country prefill functionality works as intended.Consider implementing logic within
compVal
that utilizesnewVal
andoldVal
to adjust the component's state or value accordingly.