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.
1 Answer
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.
$A.get('e.force:refreshView';).fire();
?