1

I've got a modal with a photo selector component. I have the overlay library declared in the component contained in the modal:

<lightning:overlayLibrary aura:id="photoSelector"/>

There is a button group at the bottom: Cancel calls one line of code (and it works fine):

component.find("photoSelector").notifyClose();

That closes the modal.

The other button, Send, fires an application event (which is working), and then uses the same line of code to close the modal:

var File = component.get("v.File");
console.log("handleSendPic function called for: "+ File.Title);
var sendPic = $A.get("e.c:SendPic");
sendPic.setParams({ "File" : File }).fire();
component.find("photoSelector").notifyClose();

The application event fires (and is received in another component), but the last line doesn't execute and the modal stays open.

If I comment out the application event code, then the notifyClose() works. If I put the notifyClose() line first, it works, but the modal closes before the application event can fire.

I haven't had this issue with modals before. Am I missing something obvious?

  • BTW... I also tried closing it from the parent component (from which it was launched), but that gives me a lighting-overlay-utils message in the console that says: There is no event definition for event "notify", probably because there is no component to handling it -- and it doesn't close the modal. – PatMcClellan__c Nov 15 '18 at 1:11
  • Does it work if you use a component event instead or application event? Should ideally work fine for both though. – Raul Nov 15 '18 at 1:44
  • @Raul, component event won't work here because, apparently, the Modal isn't considered part of the containment hierarchy of the component that needs to catch the event. – PatMcClellan__c Nov 15 '18 at 3:09
1

Found it. No bug in the code I shared.

The issue was a bug in the method that received the event, unrelated to catching the event. After pulling the data from the event, later in the method I referred to a variable that was null, so that method couldn't complete execution.

When I fixed that bug, the modal behavior cleared up.

I'm a bit surprised by this behavior. My understanding of firing events is that once they're fired, that component forgets about it and moves on. This behavior would suggest that it doesn't move on until the cascade of logic that results from the event has completed.

  • can you edit your answer and add the details and workaround of that particular bug? It will help others. – sanket kumar Nov 15 '18 at 4:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.