0

I have yet another event-driven question. How can I send a refresh to a parent component via the child?

Event

<aura:event type="COMPONENT" description="CDEContextTagEvent">
    <aura:attribute name="message" type="String" />
</aura:event>

Parent CMP

<aura:handler name="lightningEvent" 
              event="c:CDEContextTagEvent" 
              action="{!c.handleComponentEvent}" />

<aura:attribute name="message" type="String"/>
<p>{!v.message}</p>

<aura:iteration items="{!v.manageView}" var="row">
    <c:CDECContextTagRow view="{!row}"/>
</aura:iteration>

Parent Controller

handleComponentEvent : function(cmp, event, helper){
    var message = event.getParam("message");
    var action = cmp.get("c.CDEContextTagListController");

    action.setCallback(cmp,
        function(response) {
            var state = response.getState();
            if (state === 'SUCCESS'){
                $A.get("e.force:refreshView").fire();
            } else {
                 //do something
            }
        }
    );
    $A.enqueueAction(action);
},

Child CMP

<aura:registerEvent name="lightningEvent"
                    type="c:CDEContextTagEvent" />
        <td data-label="">
            <div class="slds-truncate" >
                <button onclick="{!c.callDeleteRecord}" 
                          class="slds-button 
                                 slds-button_icon" 
                          title="Delete Record">
                    <lightning:icon iconName="action:delete" 
                                        size="xx-small" 
                                        alternativeText="Delete"/>
                    <span class="slds-assistive-text">Delete</span>
                </button>
            </div>
        </td>

Child Controller

({
    callDeleteRecord : function(component, event, helper) {
        event.preventDefault();
        var action = component.get("c.deleteTagName");
        var currentRecordId = component.get("v.view.Id");
        action.setParams({"currentRecordId" : currentRecordId});

        var answer = confirm ("Are you sure you want to delete this tag?");
        if(answer){
            $A.enqueueAction(action);
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "type": "Error",
                "title": "Deleted!",
                "message": "The deficiency tag has been deleted successfully."
            });
            toastEvent.fire();

            var event = component.getEvent("lightningEvent");
            event.setParams({
                "message" : "MESSAGE TEST" });
            event.fire();
        }
    },
})
  • 1
    Where are you stuck? – Sebastian Kessel Apr 25 '18 at 3:26
  • This all looks correct and you are not using the message anywhere in the handleApplicationEvent method, and the event is the component type, not the application one, and you used method name handleApplicationEvent like you are handling an application type event. – itzmukeshy7 Apr 25 '18 at 6:16
  • Oops! Sorry about the naming! Fixed! I am stuck as to why the component isn't refreshing after calling delete. Confirmation alert pops up, toast message pops up, then silent... :( – Jeff Apr 25 '18 at 13:11
  • Where are the confirmation alert and the toast message fired? Do you know for sure that your server-side controller is returning successfully? – David Reed Apr 25 '18 at 13:15
  • @David Hey David, I edited it again to show where exactly it is trying to fire. Also, I'm not able to display the "message" from the parent controller which I'm assuming is due to the event not being fired properly? – Jeff Apr 25 '18 at 13:35

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.