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

STPPaymentCardTextField: changes return key behavior, adds willEndEditingForReturn delegate method #1059

Merged
merged 6 commits into from
Jan 10, 2019

Conversation

danj-stripe
Copy link
Contributor

Summary

Improves behavior when user uses the return key: both for switching between subfields
of the STPPaymentCardTextField, and to resign first responder when the field is complete.

Adds -[STPPaymentCardTextFieldDelegate paymentCardTextFieldWillEndEditingForReturn:]
to let the app developer know when the user hits the return key to leave an
STPPaymentCardTextField.

Implementing this new delegate method & calling becomeFirstResponder on the next field
in your app's payment form will smoothly move the keyboard focus from the completed
STPPaymentCardTextField into that object you chose.

Motivation

Addresses #885 and #314.

Testing

Adds basic unit tests, and I manually tested using both the CardExampleViewController and
our Standard Integration app.

There are several variations of behavior: postal code on/off, validation for US and
non-US, as well as the additional address fields in the STPAddCardViewController.

…nil`

The type signature says `nonnull`, however it returns `nil` if index+1 is out of bounds.
This only happens if the postal code field is on, which most of our testing doesn't cover.
Instead, fall through to jump back to the first invalid field.

Also add docs to this method for what it returns.
This used to "work" because `nextFirstResponderField` was returning `nil` and
first responder wouldn't move. The previous commit necessitated this fix.
This supports 'return' in any field to move to the next. If the STPPaymentCardTextField is
completely filled out and valid, and the user was in the last field, resigns first
responder instead.

Most users only see the return key in non-US countries in the postal code field. We use
the on-screen number pad keyboard for the CC number, expiration & CVC. However, with an
iPad or a hardware keyboard any field might receive the return key.
…ressed

This only notifies the app developer, and does not provide a mechanism to override the
behavior that resigns first responder.

Also adds a pair of tests.
… text field

It already had logic for cycling through the various text fields, but was missing
if the user hit the return key (instead of the Next button in our input accessory
toolbar). Now that we have the delegate method, use it to move to the first address
field too.
@danj-stripe danj-stripe merged commit 2f7ac6f into master Jan 10, 2019
@danj-stripe danj-stripe deleted the danj/feature/willReturn branch January 10, 2019 23:38
yuki-stripe pushed a commit that referenced this pull request May 3, 2022
* Add ability to mock out responses for snapshot tests

* Update comment

* renaming variable
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.

None yet

3 participants