iPhoneNumberField icon indicating copy to clipboard operation
iPhoneNumberField copied to clipboard

Callback get country code

Open Dave181295 opened this issue 3 years ago • 2 comments

The flag feature is nice, but what's the point if we don't know the country code ? Please add a Callback so when user chooses a flag and adds the a phone number, we get the country code for formatting the number later,users don't want to provide the country code

Dave181295 avatar Sep 29 '22 09:09 Dave181295

The code detection is not the responsibility of the UI component, and it's not how SwiftUI works. So you need to get the code from the logic core module instead:

import PhoneNumberKit

print(PhoneNumberKit().countryCode(for: "IR"))

Also, I've put a workaround that you can directly call the core functions within the SwiftUI View. So you can get the country code of the number if the number is completely provided:

iPhoneNumberField(
    "Title",
    text: $text,
    isEditing: $isEditing,
    formatted: true
) {
    print($0.phoneNumber?.countryCode)
}

MojtabaHs avatar Oct 15 '22 10:10 MojtabaHs

Deploy Preview for kubeapps-dev ready!

Name Link
Latest commit c848f595e270295f874dbad006a304e36bc34e5c
Latest deploy log https://app.netlify.com/sites/kubeapps-dev/deploys/63775589d3e4d50009462191
Deploy Preview https://deploy-preview-5576--kubeapps-dev.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Dave181295 avatar Oct 18 '22 06:10 Dave181295

I think the users request is valid here: The goal of formatting and validation is so that you can know that the number is valid, but the string returned in the binding is a formatted one, there should probably be a second binding which contains the full number with country code so that we can actually get that value and use it elsewhere in code. Otherwise, this just makes it look pretty.

colinmasters avatar Feb 15 '23 00:02 colinmasters

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jun 19 '23 02:06 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 03 '23 02:07 github-actions[bot]