Reputation: 391
When using displayDialogAsync() to open a dialog in Outlook, the dialog appears fine. However, when I close it with the 'X' button and try to reopen the dialog again by calling the same function, it does not work.
Looking at console logs, this error is thrown when attempting to reopen the dialog:
Callback cannot be specified both in argument list and in optional object.
How I'm calling displayDialogAsync:
Office.context.ui.displayDialogAsync(windowURL, LOGIN_DIALOG_OPTIONS, function (asyncResult) {
_dialog = asyncResult.value;
if (_dialog) {
_dialog.addEventHandler(Office.EventType.DialogMessageReceived, onDialogMessageReceived);
_dialog.addEventHandler(Office.EventType.DialogEventReceived, onDialogEventReceived);
}
});
I'm not sure what the error means, but I did try to call _dialog.clearEventHandler(Office.EventType.DialogEventReceived)
as well as setting the dialog to null. Both of these approaches did not work.
Any suggestions?
Thanks
Upvotes: 2
Views: 727
Reputation: 562
For anyone that finds this in the future, the problem is caused by displayDialogAsync
mutating the options object that is passed into it, and throwing an error when this instance is reused (as discussed in the comments on OP's answer).
So instead of:
const LOGIN_DIALOG_OPTIONS = { width: 30, height: 60 }
function showLoginDialog () {
Office.context.ui.displayDialogAsync(windowURL, LOGIN_DIALOG_OPTIONS, function (asyncResult) { ... })
}
You'll need to create a new instance of the options (or clone the object) every time you call the function:
function showLoginDialog () {
const instanceOptions = { width: 30, height: 60 }
// or const instanceOptions = _.cloneDeep(LOGIN_DIALOG_OPTIONS)
Office.context.ui.displayDialogAsync(windowURL, instanceOptions, function (asyncResult) { ... })
}
Upvotes: 0