Skip to content

Instantly share code, notes, and snippets.

@savchukoleksii
Created July 9, 2021 08:51
Show Gist options
  • Save savchukoleksii/7157e020de9ca0411d737a95d757723f to your computer and use it in GitHub Desktop.
Save savchukoleksii/7157e020de9ca0411d737a95d757723f to your computer and use it in GitHub Desktop.
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