Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Disable the spinner on the add to cart button after finishing the request (#12566)

Łukasz Adamczyk3d36356c8903
diff --git a/storefront/app/javascript/spree/storefront/controllers/product_form_controller.js b/storefront/app/javascript/spree/storefront/controllers/product_form_controller.js
index ae788af0e8..1ed84a120d 100644
--- a/storefront/app/javascript/spree/storefront/controllers/product_form_controller.js
+++ b/storefront/app/javascript/spree/storefront/controllers/product_form_controller.js
@@ -53,6 +53,7 @@ export default class extends Controller {
}
this.formTarget.addEventListener('submit', this.disableSubmitButton)
+ this.submitTargets.forEach((button) => button.addEventListener('turbo-stream-form:submit-end', this.enableForm))
}
disconnect() {
diff --git a/storefront/app/javascript/spree/storefront/controllers/turbo_stream_form_controller.js b/storefront/app/javascript/spree/storefront/controllers/turbo_stream_form_controller.js
index 296bd1817c..173167490a 100644
--- a/storefront/app/javascript/spree/storefront/controllers/turbo_stream_form_controller.js
+++ b/storefront/app/javascript/spree/storefront/controllers/turbo_stream_form_controller.js
@@ -40,8 +40,11 @@ export default class extends Controller {
await request.perform()
+ const submitEndEvent = new Event('turbo-stream-form:submit-end')
+
this.submitElements.forEach((element) => {
element.disabled = false
+ element.dispatchEvent(submitEndEvent)
})
form.ariaBusy = false
}