开发者

jQuery dialog continue click event on form validation

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 si开发者_运维技巧ze 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜