bleroy / Nwazet.Commerce

Idiomatic commerce module for Orchard CMS.
BSD 3-Clause "New" or "Revised" License
26 stars 21 forks source link

Stripe Ship Back Button Throws Invalid Entries #62

Open bleroy opened 9 years ago

bleroy commented 9 years ago

Originally reported by: Jeffrey Olmstead (Bitbucket: ems, GitHub: ems)


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.


bleroy commented 9 years ago

Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems):


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.

bleroy commented 9 years ago

Original comment by Josh Berry (Bitbucket: joshberry, GitHub: joshberry):


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".

bleroy commented 9 years ago

Original comment by Jeffrey Olmstead (Bitbucket: ems, GitHub: ems):


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

#!javascript
var BackButtonClicked = false;

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

#!javascript
    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:

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

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