I have a simple scenrio in which, Enter key press should trigger the submit on the dialog
Sample code for the dialog
sampleDialog = new YAHOO.widget.Dialog("sampleDialogContent", {
modal:true,
draggable:false,
buttons:[{
text:"Submit",
handler: submitHandler,
isDefault:true
},{
text:"Cancel",
handler: cancelHandler
}]
})
var escapeListener = new YAHOO.util.KeyListener(document, {
keys : [27]
}, {
fn:cancelHandler,
scope:sampleDialog,
correctScope:true
} );
escapeListener.enable();
var enterListener = new YAHOO.util.KeyListener(document, {
keys : [13]
}, {
fn:submitHandler,
scope:sampleDialog,
correctScope:true
} );
enterListener.enable();
In the above code Escape key listener works perfectly and Enter key listener does not work. Why?
If I change the key for submitHandler, it works again. Enter key is doing something spl
I identified the problem. In the submit handler I have some validation checks that show an alert if data is bad. When I tested I never tested with good data. So I was always hitting those alert boxes. Here comes the problem: for some reason the alert dialog also got the enter key press along with the parent dialog, so the alert dialog is collapsed and net UI effect is as if nothing happened. Now I kill the key event before actually calling the submit.