views:

428

answers:

1

I am having quite a hard time trying to find some answers with this particular dialog box action. The problem is when the user presses the "enter" (keyCode = 13) button, the dialog closes...as if the 'esc' key was pressed. I want to keep the dialog box open even when "enter" is pressed.

Fairly simple code, simple dialog box from jquery (1.2.6).

I have an ajax request populating the dialog box

var div = $("`<div>`testing`</div>`");

$.ajax({

       type      :"GET",
       dataType  : "html",
       cache     : false,
       async     : false,
       url       : WorldWideInventory.baseURL+"/templates/invoice_invoicenumber_confirm.tpl.html",
       error     : function(){ alert("Failed to Connect to Server, Please try Again");},
       success   : function(response){
                  div.html(response);
       }
});

div.appendTo("#APO_Wrapper").dialog({

            width:662,
            height:407,
            closeOnEscape: true,
            bgiframe: true,  
            modal: true,
            title: "Confirm Invoice Number",
            beforeClose: function(){return false;},
            close: function(){return false;} 

});

Thats it...this is driving crazy, anyone have any suggestions/answers to this problem? Good karma will be sent your way!!

A: 

The problem you're experiencing is because the close link is being given focus when the dialog is activated, so when the user hits enter it's effectively calling the close dialog command.

Try giving focus to another clickable element (such as a button, link, form element, etc) when the dialog is opened using the open event on the dialog, similar to:

div.appendTo("#APO_Wrapper").dialog({

            width:662,
            height:407,
            closeOnEscape: true,
            bgiframe: true,  
            modal: true,
            title: "Confirm Invoice Number",
            open: function(event, ui){ $("#someOtherSelector").focus(); }

});

See how you go with that. This doesn't happen with the current version of jQuery and jQuery UI though, so if you can update, I'd recommend that.

Jason Berry