stripe-archive / react-stripe-elements

Moved to stripe/react-stripe-js.
https://github.com/stripe/react-stripe-js
MIT License
3.03k stars 319 forks source link

Is it possible to skip to next field on completion with multiple fields? #522

Closed Sbphillips19 closed 4 years ago

Sbphillips19 commented 4 years ago

In all the examples if you use a single element which has all the fields in one input it automatically jumps over to the expiration field after validating the credit card number field.

If you want to instead have multiple fields then you need to tab or click through. Is there a way to use focus to jump from one field to the next? Can't seem to find any info on this and no examples show this functionality

Examples I am referring to:

https://stripe.dev/elements-examples/

ArtemAstakhov commented 4 years ago
if (event.complete) {
      if (event.elementType === "cardNumber") {
        elements?.getElement(CardExpiryElement)?.focus();
      }

      if (event.elementType === "cardExpiry") {
        elements?.getElement(CardCvcElement)?.focus();
      }
}

works well

asolove-stripe commented 4 years ago

The above may or may not work for your specific use-case. It does work for simple forms that are in order. There are some accessibility concerns that may make this less than ideal depending on your page layout.