I have added two inputs on product page, and I need to validate these values befor customer clicks on "Add to cart" button.
I have added on "jQuery(document).ready" funktion that assigns additional JS validation to .addToCart button. I don't know if this is correct solution, but it worked, until I have added product variants. When customer selects another variant, my additional validation is cleared. I guess, at there is some kind of form "reload"...
Så my question is, where I can add additional validation before "add to cart" at client-side
"Add to cart" - additional validation - where?
Hi,
I have added two inputs on product page, and I need to validate these values befor customer clicks on "Add to cart" button.
I have added on "jQuery(document).ready" funktion that assigns additional JS validation to .addToCart button. I don't know if this is correct solution, but it worked, until I have added product variants. When customer selects another variant, my additional validation is cleared. I guess, at there is some kind of form "reload"...
Så my question is, where I can add additional validation before "add to cart" at client-side
Kind regards
Thomas
Hey Thomas,
You should use the jQuery on method to bind to your events:
http://api.jquery.com/on/
Be avare that you should use it like this:
jQuery('body').on('submit', '.elementClass', function(){
//Do stuff
});
That way you make sure that if the element you are binding to are replaced, as in your scenario, the new element will also be bound to your event.
/Rune
Thanks! :)
/Thomas
is working on a reply...