Stripe Elements: know when card details field is empty?

3,557 views
Skip to first unread message

Tim Howell

unread,
Oct 20, 2017, 6:08:31 PM10/20/17
to Stripe API Discussion
We’re in the process of converting our application to use Stripe Elements instead of the Stripe v1 Javascript library. In our application, in some cases a user may want to record that they have previously made a credit card charge without actually processing a card. The way that we currently handle this is to check, on form submit, whether the input field that we are using to collect a credit card number is empty, and if it is then to provide an alert to the user asking whether they intended to submit an empty card number or would like to go back and enter a number. If they choose to submit with no card number then we just record the payment without involving Stripe.

We are now moving to Stripe Elements for compliance reasons. In order to keep the workflow as close to our current workflow as possible, is it possible to be notified by the elements.createToken function that the card input field is empty? I know that an error is returned when tokenization fails, but I think that only occurs if data is actually submitted. What is the cleanest way to catch the case of trying to submit with an empty field?

Thank you in advance,

—TWH

Fred Alger

unread,
Oct 20, 2017, 6:11:35 PM10/20/17
to Stripe API Discussion
Hi Tim,

Great question! Currently the best solution is to assume that the card input is empty from when it's created until you receive a `change` with `empty: false`:


We've discussed some other possibilities for this in the future, but this is the recommended approach right now—the only way for data to get into the element is by user entry, as there's no way to pre-fill or enter the information into Elements.

Please let me know if you have any other questions, I'm happy to help!

Best,
- Fred.




--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.


Reply all
Reply to author
Forward
0 new messages