jQuery Modal Form Validation not working when saving with AJAX -


i'm hoping 1 of experts here can point me in right direction jquery dialog script have been working on..

my problem: can't validation work dialog window when saving via $.ajax(). script works fine if don't save via ajax , submit form:

eg. $( ).find('form#mws-validate-event').submit();

if has time on code have left below , validation part appreciate it. have searched high , low on stackoverflow have yet find solution.

thanks.

        $("#mws-addform-dialog").dialog({                 autoopen: false,                  title: "my form / add new",                  modal: true,                  width: "480",             //working validation (no ajax)             //buttons: [{             //      text: "submit",              //      click: function() {             //          $( ).find('form#mws-validate-event').submit();             //      }}]              buttons: {             "submit": function() {              },             'save': function() {                  $.ajax({                     type : 'post',                     url : 'ajax.php?action=addnew',                     data : $('#mws-validate-event').serialize(),                     beforesubmit : function (){                         // validate data before submit?? anyone??                         //$( ).find('form#mws-validate-event').submit();                     },                     success : function(data) {                         // show ok message                         $('#mws-validate-event').find('.mws-form-message').html(data);                         alert('ok');                     },                     error: function(error){                         // show error message                         alert('error');                     }                 });              },             'cancel': function() {                  $(this).dialog("close");              }           }          });          $("#mws-addform-dialog-btn").bind("click", function(event) {             $("#mws-addform-dialog").dialog("option", {modal: true}).dialog("open");             event.preventdefault();         });         //- modal form          // validate form                 $("#mws-validate-event").validate({         //ignore: ".ignore",             rules: {                 spinner: {                     required: true,                      max: 5                 }              },              invalidhandler: function(form, validator) {                 var errors = validator.numberofinvalids();                 if (errors) {                     var message = errors == 1                     ? 'you missed 1 field. has been highlighted'                     : 'you missed ' + errors + ' fields. have been highlighted';                     $("#mws-validate-error").html(message).show();                 } else {                     $("#mws-validate-error").hide();                     }             }         });         //- validate form  

have tried validating jquery validator? of validation work , easy use.

http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -