Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tomasz Kowalski 97 posts 341 karma points
    Nov 06, 2013 @ 14:55
    Tomasz Kowalski
    0

    "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

  • Rune Grønkjær 1303 posts 2895 karma points
    Nov 06, 2013 @ 15:49
    Rune Grønkjær
    101

    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

  • Tomasz Kowalski 97 posts 341 karma points
    Nov 07, 2013 @ 08:33
    Tomasz Kowalski
    0

    Thanks! :)

    /Thomas

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies