0
$("#changePassword").validate({
        rules: {    
            newPassword: {
                required: true              
            },
            newPassword2: {
                required: true,             
                equalTo: "#newPassword"
            }               
        }
    });

Hey guys this is my validation code.

And this is my password check

    $('#oldPassword').change(function() {
        var password = $(this).val();
        $.post('/settings/check/oldPassword', { value : password }, function(data) {

            if (data == 'false') {                  
                $('#oldPassword').removeClass('valid');
                $('#oldPassword').addClass('error');
            }

        });
    });

How do I make it so the form will not submit when it has this error. I also thought jquery validation didn't submit if a form element had the class error but apparently not. The error class is getting added fine but you can still submit the form. Thanks for any help.

EDIT

Here is the form.

        <input type="text" name="oldPassword" placeholder="Old Password" value="" title="Old Password" class="hint" id="oldPassword" size="30"  /> 

    <br />
    <br />
    <input type="password" name="newPassword" placeholder="New Password" value="" title="New Password" class="hint" id="newPassword" size="30"  /> 

    <br />
    <br />

    <input type="password" name="newPassword2" placeholder="Verify Password" value="" title="Verify Password" class="hint" id="newPassword2" size="30"  /> 

    <br />
    <br />
    <input type="submit" id="submitForm" value="Change Password" />

2 Answers 2

1

You could do:

$('#oldPassword').submit(function() {
    var password = $(this).val();
    $.post('/settings/check/oldPassword', { value : password }, function(data) {

        if (data == 'false') {                  
            $('#oldPassword').removeClass('valid');
            $('#oldPassword').addClass('error');
            return false;
        }

    });
});

EDIT - if you need to valiate a value of an input by checking a remote resource you should use remote() , you definitly should not try to "confuse" the plugin by thinking that the form is invalid

Sign up to request clarification or add additional context in comments.

5 Comments

This is not working. oldPassword is just a input field not a form.
And you want to validate it when you submit the form or when you press a key?I don't understand that
I need to validate the password on the server when they change fields. Then the new password needs to be validated using jquery validate. That works fine. jquery Validate will keep the form from submitting. I just need to tell jquery validate that the old password is good or not. Take a look at my edit.
I think you should use the remote() option of the plugin that i linked in my response: this way the field is validate and if it doesn't pass avalidation the form doesn't submit.
Thanks. Remote was the function I needed.
0

You're going to have to use .submit() and not change() and return false if validation failed.

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.