0

I have an MVC application that uses data annotations validation. I also have on button submit some manual jQuery validation. I want the submit button to hide when my jQuery validation has passed and the unobtrusive validation implemented by the framework passes.

This is the code I have:

$('#btnSubmit').click(function () {
    if (!$('#Terms').is(':checked')) {
        $('.termsLabel').animate({ color: "#c71040" }, 'slow');
        $('.termsLabel a').animate({ color: "#c71040" }, 'slow');
        return false;
    }

    if ($('.wordCount').hasClass('error')) {
        $('.caption label').animate({ color: "#c71040" }, 'slow');
        return false;
    }

    if ($(form).valid()) {
        $('#btnSubmit').hide();
        $('#submitting').show();
    }

});

The (form).valid() method always seems to return false (and the hide / show is never executed) even when the form is posting.

The reason I'm doing this is I'm allowing the users to upload an image, and I don't want the user to be able to click more than once.

Any help - appreciated.

1
  • Where is form defined? $(form) seems incorrect. Commented Mar 21, 2012 at 3:11

1 Answer 1

1

I'll answer my own question.

On the form:

@using (Html.BeginForm("MyAction", "MyController", FormMethod.Post, new { @ID = "MyForm" }))

And then:

$('#MyForm').validate();

    if ($('#MyForm').valid()) {
        $('#btnSubmit').hide();
        $('#submitting').show();
    }

The problem was I didn't give my form a name, and didn't call .validate()

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

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.