views:

52

answers:

2

I've got a form that is using jQuery validation. When the user clicks the submit button, a dialog window displays thatshows the fields the user filled out along with the data the user entered. It asks the user if this information is correct. If it is, the user clicks the submit button in the dialog window and the form is submitted. If the user clicks the 'Fix it' button, the dialog window closes and the user returns to the form.

My problem is my dialog window displays when the user clicks the form's submit button even if there are errors in the form. I only want to display the dialog window if the form data is validated by jQuery. How do I do this?

I'm thinking of something like:

if (('#form').validates() == true) {
    $('#verification_dialog').dialog('open');
}

Is there a way in jQuery to determine whether the whole form has validated? Or do I have to create my own function to do this?

A: 

To get a boolean value for validation you can use:

if($('#form').validate().form()){
 ...
}
gmcalab
A: 

try

$("#form").validate({....});

if (('#form').valid()) {
    $('#verification_dialog').dialog('open');
}

more on .valid()

edit

here's my work around on that...

  var _form;
  $("#myform").validate({
    //.... other options
     meta: "validate",
     submitHandler: function(form) {
       // triggers only if form is valid....
       _form = form; // capture the form....
       $('#verification_dialog').dialog('open');
       return false; // stop submit...
     }
  })
  $('#verification_dialog').dialog({
     //.... other options
     autoOpen: false,
     buttons : {
          "Accept" : function(){             
              _form.submit(); // submit the captured form...
          }
     }
  });

quick demo

Reigel
why the vote down?... anything i missed?
Reigel
don't know how you got voted down. I changed it. I am unable to get that format to work. The dialog window never displays even though I've added an alert that shows the form is valid. I'm doing this: $('#form').submit(function(){ if (('#form').valid()) { $('verification_dialog').dialog('open'); } });I have tried this: $('#form').submit(function(){ $('#verification_dialog').dialog('open').$('#form').valid(); });That almost works, but the dialog window disappears and the form gets submitted.
please see edit...
Reigel
You are a life saver! That works!