Skip to content
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

Add UITextContentType values to text fields provided by the SDK. #870

Merged
merged 2 commits into from
Dec 20, 2017

Conversation

danj-stripe
Copy link
Contributor

Summary

This turns on QuickType suggestions for the name, email, and address fields. Also, using
a better keyboard for Payment Card fields.

For STPFormTextField, this was a lot harder than expected, due to always returning NO
from textField:shouldChangeCharactersInRange:replacementString:. There's a workaround
for the way UIKit behaves, which is only applicable for the Phone Number field right now.

Also using UIKeyboardTypeASCIICapableNumberPad in STPPaymentCardTextField if available

Per WWDC 2016, this was specifically added to
support things like credit card entry:

We’ve also localized the keyboard number pads this year. [...]
Now in some cases, you might want to specify ASCII capable number pad instead when you’re sure that the input that you have needs to be restricted to ASCII digits.
Some examples of this are credit card numbers and IP addresses.

I think this is redundant for the Credit Card Number field (just setting the
textContentType is sufficient to use this keyboard), but it'll help w/the expiration
and CVC.

These text fields fall back to using .PhonePad, apparently to avoid localized & third
party keyboards (#358), and as far as I can tell .ASCIICapableNumberPad continues to
avoid them.

Motivation

#836

Testing

Tested in the Standard Integration example app. Best tested on a device that knows an
address (simulator doesn't provide valid completions).

Both Shipping & Billing addresses are affected, and this also touches the Payment Card
text field.

Verified that enabling/using non-ASCII keyboards doesn't allow non-ASCII digits into
payment card fields.

Verified that 3rd party keyboards cannot be used for the credit card number entry.

For STPFormTextField, this was a lot harder than expected, due to *always* returning NO
from `textField:shouldChangeCharactersInRange:replacementString:`. There's a workaround
for the way UIKit behaves, which is only applicable for the Phone Number field right now.

Also using `UIKeyboardTypeASCIICapableNumberPad` in `STPPaymentCardTextField` if available

Per [WWDC 2016](http://asciiwwdc.com/2016/sessions/201), this was specifically added to
support things like credit card entry:

> We’ve also localized the keyboard number pads this year. [...]
> Now in some cases, you might want to specify ASCII capable number pad instead when you’re sure that the input that you have needs to be restricted to ASCII digits.
> Some examples of this are credit card numbers and IP addresses.

I think this is redundant for the Credit Card Number field (just setting the
`textContentType` is sufficient to use this keyboard), but it'll help w/the expiration
and CVC.

These text fields fall back to using .PhonePad, apparently to avoid localized & third
party keyboards (#358), and as far as I can tell `.ASCIICapableNumberPad` continues to
avoid them.
@danj-stripe
Copy link
Contributor Author

Unfortunately, in English on my 11.2 test device, this puts a space after the inserted content. This breaks our validation for email & zip codes (as well as having unwanted spaces in the other fields).

I plan to submit a follow up PR that relaxes validation to allow those trailing spaces, and trims spaces from these fields.

@danj-stripe
Copy link
Contributor Author

This PR currently relies on the changes from #867, and has that branch as a base.

Copy link
Contributor

@bg-stripe bg-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, just a couple questions!

@@ -156,6 +175,9 @@ - (void)updateTextFieldsAndCaptions {
break;
case STPAddressFieldTypeCountry:
self.textField.keyboardType = UIKeyboardTypeDefault;
if (@available(iOS 10.0, *)) {
self.textField.textContentType = UITextContentTypeCountryName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this autofill the full name of the country? if so, i'm not sure if autofill will correctly update contents (which should be a country code).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It does not provide quicktype suggestions (when tested on 11.2 and 11.0.1), and I think that's due to our use of the UIPickerView (which handles updating contents, etc).

This does seem potentially dangerous, because that could change in the future. I don't think this is adding anything, so I'm leaning toward removing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, +1 for removing it then.

if (@available(iOS 10, *)) {
textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
} else {
textField.keyboardType = UIKeyboardTypeNumberPad;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be PhonePad?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be, thanks for catching that!


1. UITextContentType suggestions are only available when textField is empty
2. When user taps a QuickType suggestion for the `textContentType`, UIKit *first*
calls this method with `range:{0, 0} replacementString:@" "`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, nice comment!

@danj-stripe danj-stripe changed the base branch from danj/bugfix/separate-payment-and-address-text-fields to master December 19, 2017 20:05
Copy link
Contributor

@bg-stripe bg-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@stripe-ci stripe-ci assigned danj-stripe and unassigned bg-stripe Dec 19, 2017
@danj-stripe danj-stripe merged commit 3c70479 into master Dec 20, 2017
@danj-stripe danj-stripe deleted the danj/bugfix/text-content-type branch December 20, 2017 00:14
danj-stripe added a commit that referenced this pull request Dec 20, 2017
…ng the property.

Fixes a user-interaction issue (knowingly) introduced by #870.

When selecting email or zip code autocompletion suggestions, they fail validation. US zip
codes would fail immediately, while email addresses waited until the field lost focus.
This was an unpleasant UX experience.

This is both a very concise fix, but also one I like. It keeps the contents of the text
field unchanged, and does not interfere with editing in any way. Leading & trailing spaces
are simply ignored while validating, and they are likewise ignored when considering what
the logical contents of the cell/text field are.

This results in the trimmed string being persisted to the server, and the trimmed string
being passed around the payment context (like copying to the other address type)
danj-stripe added a commit that referenced this pull request Dec 20, 2017
…ng the property. (#872)

Fixes a user-interaction issue (knowingly) introduced by #870.

When selecting email or zip code autocompletion suggestions, they fail validation. US zip
codes would fail immediately, while email addresses waited until the field lost focus.
This was an unpleasant UX experience.

This is both a very concise fix, but also one I like. It keeps the contents of the text
field unchanged, and does not interfere with editing in any way. Leading & trailing spaces
are simply ignored while validating, and they are likewise ignored when considering what
the logical contents of the cell/text field are.

This results in the trimmed string being persisted to the server, and the trimmed string
being passed around the payment context (like copying to the other address type)
jaimepark-stripe added a commit that referenced this pull request Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants