Skip to content

Commit

Permalink
show loading animation on checkout button after form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed May 22, 2024
1 parent d79c8c0 commit 21841fd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions public/js_original/cart-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function updateCart(e) {
}

async function checkout() {
// set loading animation on checkout button to prevent multiple form submissions
document.querySelector("#checkout-btn").setAttribute("aria-busy", "true");

const myCart = Cart();
const items = myCart.getItems();

Expand All @@ -63,6 +66,9 @@ async function checkout() {
body: JSON.stringify(data),
});

// stop loading animation
document.querySelector("#checkout-btn").setAttribute("aria-busy", "false");

if (response.ok) {
// Clear cart items from localStorage if checkout is successful
myCart.clear();
Expand Down

0 comments on commit 21841fd

Please sign in to comment.