EvgeniyMukhamedjanov / liquid-ajax-cart

Build a Shopify Ajax-cart without JavaScript coding
https://liquid-ajax-cart.js.org
191 stars 22 forks source link

Clear errors on another product form when a different product form is submitted. #13

Closed james0r closed 2 years ago

james0r commented 2 years ago

Just migrated to version 1.10. You're doing a killer job, this thing is freaking awesome.

Got a question though, so as title says, on my collections page i want other product request errors to be hidden when any other product add-to-cart is attempted. What's the best way to handle this? via an attribute or listen for requests in JS? Thanks!

Store: https://store2-0-playground.myshopify.com/ Password: playground

Code for each grid item --> https://gist.github.com/james0r/aa88aa856a82ecd151f375204ab98b4c

image
EvgeniyMukhamedjanov commented 2 years ago

Hey @james0r , thank you! I'm happy to hear that you continue to use Liquid Ajax Cart. In order to remove the form error messages you can use the following snippet:

subscribeToCartAjaxRequests( requestState  => {
  if ( requestState.requestType === 'add' ) {
    document.querySelectorAll('[data-ajax-cart-messages="form"]').forEach(element => element.innerHTML = '')
  }
}

I'll convert the issue to discussion.