0

I have a Quick Action with a lightning component, it's a form for the creation of records. I make a button (Save & New) in the modal panel, but i don't know how to reload the entire form or clear all the fields and go back to the top of the form. I don't know if there is a way to do this.

2
  • which method are you using to create records? custom LDS in that form or using $A.get("e.force:createRecord")? After Success Callback, have you tried using $A.get('e.force:refreshView';).fire(); ?
    – Nithesh N
    Jan 11, 2019 at 18:12
  • I'm calling an apex class where I use the upsert method. I tried using $A.get('e.force:refreshView';).fire(); but that it's only refreshing me the page behind the modal panel
    – rubncin
    Jan 16, 2019 at 9:02

1 Answer 1

0

I faced the same problem before, the solution I implemented is to create a dynamic component every time and replace the existing component. That way whole component is refreshed.

  • Following is the template for implementing that method.
<aura:component description="ModalContainer">
    <aura:attribute name="recordCreator" type="Aura.Component" />
    <aura:handler name="CmpEvent" event="c:CmpEvent" action="{!c.handleComponentEvent}"/>

    {!v.recordCreator} 

    <!-- Dynamically create the Component <c:RecordCreator refresh="{!v.refresh}" description="Form Component for record Creator" /> -->

</aura:component>




/*ModalContainerController.js*/
({
    doInit : function(cmp, event, helper) {
        helper.createComp(cmp);
    },

    handleComponentEvent : function(cmp, event) {
        helper.createComp(cmp);
    }
}}

/*ModalContainerHelper.js*/
({
    createComp : function(cmp) {
        $A.createComponent(
            "c:recordCreator",
            {
                "aura:id": "findableAuraId",
            },
            function(newCmp, status, errorMessage){
                //Add the new button to the body array
                if (status === "SUCCESS") {
                    cmp.set("v.recordCreator", newCmp);
                }
            }
        );
    }
})



/* CmpEvent.evt */
<aura:event type="COMPONENT">
</aura:event>

/* RecordCreator.cmp */
<aura:component description="ModalContainer">
    <aura:registerEvent name="CmpEvent" type="c:CmpEvent"/>
    <!-- Form Logic-->
</aura:component>


/* RecordCreatorController.js */
{
    OnSuccessUpsert : function(cmp, event) {
        var cmpEvent = cmp.getEvent("CmpEvent");
        cmpEvent.fire();
    }
}

Let me know if it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .