views:

305

answers:

2

On pdf downlaod link need to open a jQuery dialog and have a form taking name, email and a confirmation checkbox.

There will be some validation on the fields eg. required min and max size etc...

Have initialised the dialog on page load and the dialog is opened on pdf download link.

$("#dialog").dialog({
 bgiframe: true,
 autoOpen: false,
 modal: true,
 buttons: {
  'Continue': function(){
   var valid = true;
   valid = valid && checkExists(name, 2, 50);
   //valid = valid && checkEmail(email);
   valid = valid && checkTrue(agree);

   if(valid) {
    //ajax call to controller
    return true;
   }
  },
  'Cancel': function(){
   $(this).dialog('close');
  }
 } 

});

$("a.download-document").click(function(){
 $("#dialog").dialog('open');
});

The problem I am having is that because I have no return false on the click event it will open the dialog but then continue with the click event.

How do I get the click event to only continue when the form is submitted and the validation OK?

A: 

One simply way is to always return false from the link click handler and then use window.open from the dialog's callback handler to download the pdf.

kgiannakakis
A: 

Simply add an else clause to the if (valid) statement. It should read:

if (valid) {
   // ajax call to controller
   return true;
}
else return false;

The click will not fall through.

bschappel