0

I have a custom lightning component that calls another one via event and retrieve specific data. Problem is that I can call my component many times and every time I enter this component again from another page or section it handles previous and actual one:

Root component:

.cmp:

<aura:handler event="c:BI_LEX_LayoutSectionsEVT" action="{!c.handleLayoutEvent}"/>
<aura:registerEvent name="appEvent" type="c:BI_LEX_ConfirmMessageEvent"/>

.js:

 handleLayoutEvent : function(component, event, helper){
    var params;
    var message;
    var sectionName = component.get("v.sectionName");
    console.log('sectionName: ' + sectionName);
    if(event.getParam("fieldsBySectionMAP").hasOwnProperty(sectionName)){
        component.set("v.requiredFieldLIST", event.getParam("requiredFieldMAP")[component.get("v.sectionName")]);
        component.set("v.readonlyFieldLIST", event.getParam("readonlyFieldMAP")[component.get("v.sectionName")]);
        component.set("v.labelByNameMAP", event.getParam("labelByNameMAP"));
        component.set("v.recordTypeId", event.getParam("recordTypeId"));
        component.set("v.fieldsBySectionMAP", event.getParam("fieldsBySectionMAP")); 
        component.set("v.dependentPicklistValuesMAP", event.getParam("dependentPicklistValuesMAP"));
        helper.generateRecordForm(component,event);     
    }
    else{
        message = 'No se encuentra la sección dentro del layout: ' + sectionName;
        params = {"title":"Error","message":message,"duration":10000,"type":"error"};
        helper.generateToast(params);
    }
},

Data retriever component:

cmp:

<aura:registerEvent name="appEvent" type="c:BI_LEX_LayoutSectionsEVT"/>
<aura:handler event="c:BI_LEX_ConfirmMessageEvent" action="{!c.handleLayoutEvent}"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

.js:

({
doInit : function(component, event, helper) {
    var params;
    var result;
    var message;
    var action = component.get("c.retrieveLayoutSection");
    action.setParams({
        "recordId" : component.get("v.recordId")
    });
    action.setCallback(this, function(response){
        if(response.getState() === 'SUCCESS'){
            result = response.getReturnValue();
            if(result.success){
                if(result.hasOwnProperty('requiredFieldMAP')){
                    component.set("v.requiredFieldMAP", result.requiredFieldMAP);    
                } 
                if(result.hasOwnProperty('readonlyFieldMAP')){
                    component.set("v.readonlyFieldMAP", result.readonlyFieldMAP); 
                }
                if(result.hasOwnProperty('labelByNameMAP')){
                    component.set("v.labelByNameMAP", result.labelByNameMAP);
                }
                if(result.hasOwnProperty('recordTypeId')){
                    component.set("v.recordTypeId", result.recordTypeId);
                }
                if(result.hasOwnProperty('fieldsBySectionMAP')){
                    component.set("v.fieldsBySectionMAP", result.fieldsBySectionMAP); 
                }
                if(result.hasOwnProperty('dependentPicklistValuesMAP')){
                    component.set("v.dependentPicklistValuesMAP", result.dependentPicklistValuesMAP);
                }
                component.set("v.dataLoaded", true);
                //If bypass
                if(component.get("v.bypass")){
                    helper.retrieveData(component, event);    
                }
            }
            else{
                message = result.message;
                params = {"title":"Error","message":message,"duration":10000,"type":"error"};
                helper.generateToast(params);    
            }
        }   
        else{
            message = helper.getErrorMessage(response.getError()[0]);
            params = {"title":"Error","message":message,"duration":10000,"type":"error"};
            helper.generateToast(params);
        }
    });
    $A.enqueueAction(action);   
},
handleLayoutEvent : function(component, event, helper){
    var bypass = event.getParam("bypass");
    component.set("v.bypass", component.get("v.dataLoaded") ? false : bypass);
    component.set("v.dismissBypass", component.get("v.dataLoaded") ? true : false);
    event.stopPropagation();
    if(component.get("v.dismissBypass")){
        helper.retrieveData(component, event);      
    }
},

})

Both events:

BI_LEX_ConfirmMessageEvent:

<aura:event type="APPLICATION" description="Event template">
    <aura:attribute name="bypass" type="Boolean" default="false"/>
</aura:event>

BI_LEX_LayoutSectionsEVT:

<aura:event type="APPLICATION" description="Event template">
    <aura:attribute name="recordTypeId" type="String"/>
    <aura:attribute name="labelByNameMAP" type="Map"/>
    <aura:attribute name="fieldsBySectionMAP" type="Map"/>
    <aura:attribute name="requiredFieldMAP" type="Map" default="{}"/>
    <aura:attribute name="readonlyFieldMAP" type="Map" default="{}"/>
    <aura:attribute name="dependentPicklistValuesMAP" type="Map" default="{}"/>
</aura:event>

How can I stop every BI_LEX_LayoutSectionsEVT after succeding?

Regards,

  • can you try event.stopPropagation() in the event handler – Vidhyasagaran Muralidharan Apr 25 at 16:44
  • @VidhyasagaranMuralidharan I already tried that but still not working. – molinet Apr 26 at 6:43
  • can you add more details on the question. – Vidhyasagaran Muralidharan Apr 26 at 20:48
  • @VidhyasagaranMuralidharan sorry for the delay. Busy at work. I just tried calling event.stopPropagation() on handleLayoutEvent js method from Data retriever component and it's not working. – molinet Apr 30 at 10:52
  • Yes got it.Can you add more details aura application it is placed, class details if any and two components are parallel or the inner components. – Vidhyasagaran Muralidharan Apr 30 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.