Borales / yii2-phone-input

Yii2 International telephone numbers
Other
133 stars 54 forks source link

Validation Issues #14

Open mcki0127 opened 8 years ago

mcki0127 commented 8 years ago

Thanks for an awesome Yii extension!

I'm having trouble with validation. I can't get any numbers for any countries to validate properly, even when I type in the number shown in the placeholder. It always shows "The format of Phone is invalid."

The situation improves if I add 'nationalMode' => false. The number will save to db in format +16515551234 for US. However, when I return to the form, the initial value shows (651) 555-1234 with the error message "The format of Phone is invalid." until I select US from the dropdown, in which case it adds +1 to give +1(651) 455-0715. When I post that number, it saves to the db as +16515551234.

Why is it showing format (555) 555-5555 when national mode is false? And why do I need to select the country every time just to pass validation for an existing number? Thanks for any help.

Borales commented 8 years ago

@mcki0127 thank you for your report, I will check it.

zz commented 7 years ago

@mcki0127 I think this is not a bug :) check this doc http://jackocnr.com/node_modules/intl-tel-input/examples/gen/hidden-input.html

mcki0127 commented 7 years ago

@zz Thanks for the input! I've been having trouble configuring this extension, so I've gone back to a simpler validation for now. Hopefully down the road I can revisit this and make it work.

mcki0127 commented 7 years ago

The hidden input works beautifully as long as nationalMode is false. :-) It still doesn't work with nationalMode set to true.

Borales commented 7 years ago

@mcki0127 sorry for a huge delay with my response. Are you using PhoneInputBehavior within your model? I haven't explored the whole intl-tel-input plugin sources yet, but you can try to switch PhoneInputBehavior::$displayFormat to national.

Borales commented 7 years ago

@mcki0127 currently - this extension requires configuration in several places (in model, in widget etc), so you have to pay attention while using it.

Borales commented 7 years ago

@mcki0127 I think I can add this logic for the hidden input, but to be honest - I don't like this type of "hacks"

mcki0127 commented 7 years ago

@Borales I know what you mean. I'm thinking if the hidden input "hack" is not built into the intl-tel-input plugin, then it probably doesn't need to be built into yours. Just so people are alerted to use it when posting the number. I do appreciate your help.

Borales commented 7 years ago

@mcki0127 they have this section: https://github.com/jackocnr/intl-tel-input#troubleshooting with the description of hidden input trick. But still - it requires some JS code. But we should rely on the worst-case scenario - somebody could have JS disabled and will try to submit this form - the trick won't cover it

Borales commented 7 years ago

@mcki0127 hm.. I didn't think that the plugin won't be loaded as well at first :) well, probably I will try to play with this trick

reastyn commented 7 years ago

32 Would fix this issue and the widget would start working with newest version of intl-tel-input

kussberg commented 6 years ago

Is there already a fix for this issue, i am experiencing the same problem. First time when i enter the phone number with country code "+491234567890" it saves to the DB "+491234567890". When page refreshes i see in the field just "01234567890" and when i save the form it overrides the value in the DB to "01234567890". Tried both nationalMode true/false, nothing works.