-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How to get Country code to populate on validation failure when phone number is populated #715
Comments
Hi there. What do you mean by "When form reloads"? Do you mean when you reload the page? If so, how are you adding the number in your form? In the html input value attribute? Or are you setting it using JS (and if so how)? Also please give me an example of a phone number that you're using that isn't working. (I'm afraid I'm not familiar with |
unfortunately can't share the whole form. I have one big form validation. This where I think the problem is in js
I need to add an else to retrieve defaultCountry from the form, or it should auto populate.
|
So, I'm using hiddeninput to do a post, I have other validations that need to be done, if any validations fail, I'm able to get the value of PhoneNumber, but I lose the selectedCountry. I hope that explains it. |
Are you dealing in full international numbers e.g. "+447947123456"? This is how we recommend you use the plugin. You can get the number in this format even when using |
Not exactly. So, the drop drown populates, on first load, with country based on ip. I want to change the country code to something else, I do manually, then I put it in thre rest of the number. BAsically I want the functionality of https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/hidden-input.html |
It wont. If you have |
okay, I have nationalMode set to true, so you are saying before we do our form submit I should call setNumber? |
I think the problem is that when I initialize, with the input box field, example based on your example above https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/hidden-input.html phone number is full format in javascript but when I form submit, and error back, I reinitialize not on fullphonenumber the hidden field but the active field. |
I guess I need a way to get country code out of the hidden field fullphonenumber |
Don't worry about the hidden field - you shouldn't be touching that - leave it to the plugin. You just re-initialise the plugin with the full international number and everything should be fine. If you're still having problems, can I ask that you break it down into really clear simple steps, with example numbers etc, as I'm struggling to understand exactly where the problem is. |
got it, I understand it's super difficult over github, I wish I could share the full code. Thanks for your quick support it's a great plugin btw kudos. |
Hey, I found a solution to my problem the issue, is when we do a post After I throw a validation error on Submit for a traditional form post. the library initalizes the value fron NewUser_PhoneNumber where the value is the formattedforDisplay in national mode. I added a little bit of code, to set the value based on iso code, from a hidden field I had on the page that captured isocode. Please take a look below.
|
Sure, whatever works for you. If you're happy then feel free to close this issue. But I would say: you really shouldn't need to be handling any extra fields like PhoneIso2 or PhoneDialCode (unless you need to use those values elsewhere in your app) - you should be able to just handle one string which is the full international phone number. If you have a full international number in the input when you init the plugin then it will automatically set the flag for you, and automatically re-format the number to national format for you e.g. if you init the plugin on an input with value "+447733123123" then it will automatically select UK flag and format the number as "07733123123". |
Closing due to inactivity. |
IMPORTANT: please note that the autoFormat feature (format-as-you-type) was removed in v8.0.0 - read more here: #346. Please do not open any new issues about this topic.
IMPORTANT: we use libphonenumber for formatting and validation - if your issue relates to one of these things, please check their test site first and if you see the problem there please file an issue with them instead: https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html
Steps to reproduce
Expected behaviour
When form reloads, it shoudl automatically select country code because it was populated, along with phone number
Actual behaviour
form reloads, with phone number field populated, but country dial code is not selected,
Initialisation options
The text was updated successfully, but these errors were encountered: