function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sivakumar S CSivakumar S C 

Removing registered event

Hi,

I am developing an application in salesforce lightning. I have a dashboard page and after clicking any menu it will navigate to particular component. I have created the header as a separate component and included in other components. I have action buttons for the body in header component. Let's say, I have a component A which has a user form and to save the form after filling these details i have "save" button in header component. To trigger the events i used a registered event in header components like below,

    <aura:registerEvent name="renewalPriceSaveEvent" type="ESRV:RenewalPriceSaveEvent"/>

And on button click i fired the event in header controller,

        var appEvent = $A.get("e.ESRV:RenewalPriceSaveEvent"); 
        appEvent.fire();

In body component i handled that event like this,

    <aura:handler event="ESRV:RenewalPriceSaveEvent" action="{!c.onSave}"/>

And called save method which works fine for the first time. The problem is when i again go to dashboard and again come to same page and click save button means the event is triggered twice. Is there any way to remove event if exists before firing? 

 
Veenesh VikramVeenesh Vikram
Hi Siva,

I dont thhink you can remove an event once your component has registered it.
However with some tweaks in code, you might be able to handle the scenario you are facing.

When the button is clicked for the first time, in the JS controller, you set a value (kind of a flag) in an atribute of your component which is firing the event.
//Assuming default value of myFLAG Attribute is false
if(component.get("v.myFLAG") == false){
    component.set("v.myFLAG",true); 
    var appEvent = $A.get("e.ESRV:RenewalPriceSaveEvent"); 
    appEvent.fire();
}

Hope this helps!

Veenesh
Sivakumar S CSivakumar S C
Hi Veenesh,

It won't works if i need to save the form for second time.