12

In magento1 we can check validation like this:

var formToValidate = $('form-validate');
    var validator = new Validation(formToValidate);
    if(validator.validate()) {
        // Here we can code after validation.
    }

but in magento2 i want to check all validation but don't want to submit form after success. so how can I perform with magento2 form?

18

Try this:

require(["jquery"], function ($) {
    $(document).ready(function () {
        $('#my-button-name').click(function () { // The button type should be "button" and not submit
            if ($('#form-name').valid()) {
                alert("Validation pass");
                return false;
            }
        });
    });
});

Hope this helps!

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.