2

In the script below, I'm trying to capture the success event of the validation engine (all form element's validation criteria are satisfied) without submitting the form.

The idea is to disable the submit button until the validation is met, then I'd like to enable it. (The validationEngine examples I've seen appear to require the submit button to be enabled in order to submit the form, then its validated after the submit)

However, I can't get the "valid" method in my validate() function to fire. Any ideas what I'm doing wrong?

    $(document).ready(function() {
        /* disable the submit button until required form elements are enabled */ 
        $('#btnEcommidEdit').attr('class','button disabled');
        $('#btnEcommidEdit').attr("disabled","disabled");

        /* initiate validation */
        $("#form1").validationEngine(
        {
            inlineValidation: true
        });

        /* check form elements to enable submit button */
        $('#email2,#confirm1,#confirm2').change(function() {
            validate();
        });
    });

    function validate(){
        var valid = $("#form1").validationEngine();
        if (valid)
        $("#btnEcommidEdit").attr('disabled','');
        else
        $("#btnEcommidEdit").attr("disabled","disabled");
        }

2 Answers 2

1
function validate(){
    alert("validate");
    var valid = $("#form1").validationEngine();
    alert('Validation Engine returned : ' + valid);
    if (valid == true) {
        $("#btnEcommidEdit").prop("disabled",false);
        $("#form1").submit();
    } else {
        $("#btnEcommidEdit").prop("disabled",true);
        return false;
    }
Sign up to request clarification or add additional context in comments.

3 Comments

The problem is that the valid variable does not appear to hold the success/fail value ofthe validationEngine() method. I need the correct test there.
So, in your validate() function, the valid variable is returning false? Then you need to see what's going on in that .validationEngine() method. Have you tried "valid == true", like this?
It returns true, regardless if all the validation elements are valid. I think I'm using the wrong test.
1

Use this event to catch if the form is valid or not :

submitHandler: function (form) {
    // for demo
    if ($(form).valid()) {
        // valid
    } else {
        //do some error handling
    }
    return false; // to not submit form
}

or simple use $(form).valid()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.