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

Fix bugs around STPPaymentCardTextField becomeFirstResponder #855

Merged

Conversation

danj-stripe
Copy link
Contributor

@danj-stripe danj-stripe commented Dec 13, 2017

Summary

Previous implementation of nextFirstResponderField would return nil if all fields were
valid, which blocked programatic calls to becomeFirstResponder.

It also used to cycle through the fields every time it was called, which doesn't seem
right. It feels more natural for the default first responder to be either the first
invalid field or the last field. This puts the insertion point at the right place
to start deleting.

We do want to move to the next field (ignoring whether fields are valid or not) when the user fills the current field with valid text. This matches the web elements behavior, and feels better as they proceed through, instead of jumping around (possibly earlier, possibly to the end)

Motivation

Fixes #841

Testing

Manual testing through the Standard Integration. I also added a unit test for this
behavior. Some of the things it verifies:

  • becomeFirstResponder should not change the first responder if one of the STPPaymentCardTextField subfields is already first responder
  • becomeFirstResponder should take the user to the first invalid field when called
  • becomeFirstResponder should make the last sub-field first responder when all the fields are valid

Previous implementation of `nextFirstResponderField` would return `nil` if all fields were
valid, which blocked programatic calls to `becomeFirstResponder`.

It *also* used to cycle through the fields every time it was called, which doesn't seem
right. It feels more natural for the `nextFirstResponderField` to be either the first
invalid field *or* the last field. This puts the insertion point at the right place
to start deleting.

It also feels better if the user manually changes to the expiration field before entering
the card number: once the expiration is valid the firstResponder jumps back to numbers.
Then, once they complete numbers, it jumps to the CVC.

I also added a test for this behavior. Some of the things it verifies:

* becomeFirstResponder should not change the current first responder if the current field isn't valid yet
* becomeFirstResponder should take the user to the first invalid field when called
* becomeFirstResponder should make the last sub-field first responder when all the fields are valid
@bdorfman-stripe
Copy link
Contributor

We sync'ed offline on this. Dan is going to make some tweaks.

…e next field, even if others are invalid

It's good to have the explicit progression through fields. Keep the previous behavior that
when they're on the last field and finish filling it out, take them back to the first
invalid field.

Also, update `canBecomeFirstResponder` and `becomeFirstResponder` to *never* change which
field is the first responder, if one of the subfields already is. If there isn't one,
use either the first invalid field or the last field.

Updates tests to reflect the new expected behavior.
Copy link
Contributor

@bdorfman-stripe bdorfman-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

@danj-stripe danj-stripe merged commit 7516da2 into master Dec 14, 2017
@danj-stripe danj-stripe deleted the danj/bugfix/841-paymentcardtextfield-becomeFirstResponder branch December 14, 2017 20:01
danj-stripe added a commit that referenced this pull request Dec 15, 2017
danj-stripe added a commit that referenced this pull request Dec 18, 2017
mludowise-stripe pushed a commit that referenced this pull request Mar 15, 2022
* Add parameters

* Migrate to the new API

* Remove Link payment details from authentication context

* Cleanup and add test

* Cleanup

* Use testing publishable key

* Allow sending CVC

* Cleanup

* Handle client-side error
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