Created
July 9, 2021 08:51
-
-
Save savchukoleksii/7157e020de9ca0411d737a95d757723f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serialize from "form-serialize"; | |
export function addToCartSubmit(event) { | |
event.preventDefault(); | |
const form = event.target; | |
let formData = serialize(form, { | |
hash: true, | |
disabled: true, | |
empty: false | |
}); | |
if (Array.isArray(formData.event_id)) { | |
formData.event_id = formData.event_id.shift(); | |
} | |
form.classList.add("adding"); | |
document.dispatchEvent( | |
new CustomEvent("product:add", { | |
detail: { | |
items: [formData], | |
callback: () => { | |
setTimeout(() => { | |
form.classList.remove("adding"); | |
}, 500); | |
}, | |
errorCallback: () => { | |
form.classList.remove("adding"); | |
} | |
} | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment