Stripe Ship Back Button Throws Invalid Entries

Issue #61 closed
Jeffrey Olmstead
created an issue

When the Stripe Back button is pressed it throws invalid errors due if you don't have the form filled in. Of course, we don't want client side form validation being done on the Back button being pressed as we are not saving the data anyway. Will try to get a fix but listing this here for anyone else who might run into the issue.

Comments (4)

  1. Jeffrey Olmstead reporter

    My "simple" fix was to add in a javascript variable:

    var BackButtonClicked = false;
    

    Then I added in an event handler for the back button click event:

        backButton.click(function (e) {
            BackButtonClicked = true;
        });
    

    Then on the form submit event I just check to ensure it wasn't the back button that was clicked:

            if (!BackButtonClicked) {
                var validated = true,
                .........
    

    and that works out great. See anything that could go wrong with that?

  2. Josh Berry

    I don't see anything wrong with it. However, it might be a little more standard if you use the formnovalidate attribute on the back button and check for that on the submit event. This way if someone wants to swap out their own client-side validation framework or let the browser do it's thing it will more than likely "just work".

  3. Jeffrey Olmstead reporter

    I thought about trying to access the button clicked but I couldn't find anywhere in jQuery that allows you to get this access. You can, of course, use it if you do the validation on the actual button clicked but it is best to do the form validation on the form submission. This is why I did the little hack of manually recording which button was clicked. I would love to learn about the form no validate approach as it would be cleaner. Thanks for letting me know.

  4. Log in to comment