PDA

View Full Version : Basic MessageBox.show does not call its callback function



rbraddy
6 Mar 2013, 1:15 PM
Hi,

I have copied the following code from a working project into a new project, and it does not call the async callback "fn" for some reason. This code is called within a Delete button handler callback:



var msgStr;
msgStr = "Are you sure you want to delete '" + theTarget + "' ?";
Ext.MessageBox.show({
title:'Delete Confirm',
msg: msgStr,
buttons: Ext.MessageBox.YESNOCANCEL,
fn: confirmDelete,
icon: Ext.MessageBox.WARNING
});


The message box displays correctly. When the "Yes" button is pressed, nothing happens (in debugger in Chrome or Firebug, the callback event confirmDelete() is not triggered). No console errors. I also tried an inline config function "fn: function(btn, text, options) { ... }" and it does not get called, either.

Thoughts on how to resolve/troubleshoot? Clearly, the MessageBox is not calling my callback for some reason... (do I need to drop down into ExtJS debug land to resolve??)

Weird thing is, nearly this exact code is working in all my other projects.

Thanks
Rick

myExtJsUname
6 Mar 2013, 2:11 PM
I'm almost afraid to answer this because I'm really not that confident an ExtJs user myself but, just in case it helps, the first thing I'd look in to is whether the "confirmDelete" function is actually in scope when you make the Ext.MessageBox.show call.

Sorry if this doesn't help and just confuses the issue but so many people help me in this forum, I thought that since I actually had an idea, I should post it.

Good luck!
jtm

rbraddy
6 Mar 2013, 2:16 PM
Thanks for the response. That could be it, except there's no error message in the console window (the function's not being called), and originally there was just a configured "fn: function()..." statement inline, and it does not get called either.

myExtJsUname
6 Mar 2013, 2:23 PM
Can you put a debugger; statement just before your "Ext.MessageBox.show" line and see if confirmDelete has a value at that time or if it's just null?

rbraddy
6 Mar 2013, 2:50 PM
Yes. It is a valid function of the controller:

42239

devtig
18 Mar 2015, 4:04 AM
Exact same thing here. Weird. Rewriting to
Ext.MessageBox.confirm(title, message, function(buttonId) {console.log(arguments)}); didn't help to get the callback called either.

@rbraddy (How) did you get it solved?

I'm sure it's due to some other button event handler sitting in the way. Maybe that interrupts the event and prevents it from reaching this single event handler...

...debugging other event handlers now, will update here later...

Yes, what I assumed was indeed the case. Another generic button event handler that I created, did not handle 'yes' and showed another MessageBox telling that the user that the button is not functional yet. That cancelled the event for the original MessageBox. I removed the second MessageBox and the callback worked.

rawsonkara
20 Mar 2015, 9:37 AM
You need to declare your scope, if you don't it will use your messagebox's scope instead. here is an example one of our messagebox classes.



Ext.define('ContentSchedule.components.SaveConfirmMessageBox', {
extend: 'Ext.window.MessageBox',
modal: true,
width: 600,
height: 150,
id: 'saveConfirmMessageBox',
cls: 'cs_messageBox_saveConfirm',
xtype: 'saveConfirmMessageBox',
layout: {
type: 'vbox',
align: 'stretch'
},
initComponent: function () {
this.callParent(arguments);
},
showMask: function (scope, callback) {
this.show({
title: ContentSchedule.lang.StringBundle.pendingChangeMessage,
buttons: Ext.Msg.YESNOCANCEL,
icon: Ext.Msg.QUESTION,
scope: scope,
fn: callback,
msg: ContentSchedule.lang.StringBundle.pendingChangeMessageBody
});
}
});


the showMask function is a helper function that calls the base .show() function. This is done so that we can explicitly inject the scope and callback function based on the various view components which might trigger this confirmation to be shown.