#Liam Wilkinson - programmatic validation
1 messages · Page 1 of 1 (latest)
Hi 👋 the submission/confirmation is handled by calling stripe.confirmPayment, and as far as I know that can be called from anywhere within your JS code.
Hi Toby, yup I'm using stripe confirm payment right now but I don't want to run confirm payment until the user fills out the custom name field on the page. I know that confirm payment triggers validation, is there a publicly exposed function I can use to trigger that same validation logic without submitting the information?
Are you referring to the validations that, for example, return an error if the card was declined?
So those sorts of errors I assume can only be received if I actually call confirmPayment. I just want to display front end validation errors for if the customer hasn't filled out say the credit card field or CCV field.
Oh gotcha
Essentially the errors that are triggered by .on('change', but without the user having actually modified the form.
Listening to those change events is going to be best way to handle that. You'll essentially want to track the state of the element(s) yourself, and then throw your own error if the user attempts to submit before everything is ready.
Is there any way for me to then highlight the field if the user hasn't filled the form out then or is that not a publicly accessible method?
I don't think so, but am looking.
I'm not entirely sure if it's possible, but if it is then it's likely done by leveraging either:
The appearance API if you're using the Payment Element: I haven't played with this much, but the options related to warnings would be my guess on what might be applicable.
https://stripe.com/docs/stripe-js/appearance-api#additional-variables
Or the Style object if you're using Card Element(s): I think invalid would be the state to make changes to with this approach
https://stripe.com/docs/js/appendix/style
Ok, thanks I'll look into this.