Clear the value while adding to Add to cart

salu
Mega Guru

Hello All,

I need to clear the of the catalog form while clicking on add to cart.I wrote a script in on submit to clear the value.But it will not store in the table.Can you please suggest a solution for this?

Thanks

1 ACCEPTED SOLUTION

andrew_lawlor
Giga Expert

So, it sounds like you want to clear all form fields onSubmit, when a user clicks the add to cart button? It also sounds like, since you're clearing form values onSubmit, before the RITM is added to the user's cart, all of the variable values are empty in the cart.



I think a simple way around this would be to redirect the user on the client-side with an onSubmit client script. You could redirect the user to the current catalog item - grab its unid dynamically - using window.location = x; This will add the item to the user's cart and reload the current form.


View solution in original post

8 REPLIES 8

Mujtaba Amin Bh
Mega Guru

what is that you want to clear?


andrew_lawlor
Giga Expert

So, it sounds like you want to clear all form fields onSubmit, when a user clicks the add to cart button? It also sounds like, since you're clearing form values onSubmit, before the RITM is added to the user's cart, all of the variable values are empty in the cart.



I think a simple way around this would be to redirect the user on the client-side with an onSubmit client script. You could redirect the user to the current catalog item - grab its unid dynamically - using window.location = x; This will add the item to the user's cart and reload the current form.


So, for instance:


(this part may change depending on how your catalog is set up)


var unid= gel('sysparm_item_guid').value;


window.location = '/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=' + unid;


I take that back - that's a terrible solution! You can just use location.reload(true); instead.