1

I have added a qty box with add to cart button on product list page like

<input type="number" min="1" name="qty" maxlength="12" value="1" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty" data-validate="{'required-number':true,digits:true,'validate-greater-than-zero':true}"/>

How I can validate this?

3
<script>
    require(["jquery"], function ($) {
        $(document).ready(function () {
            $('.tocart').click(function () {
                $Obj = $(this).closest('form');
                if ($Obj.valid()) {
                    $Obj.submit();
                } else {
                    return false;
                }
            });
        });
    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.