If you really care about the save event only, then you need to attach a handler for the force:recordSaveSuccess
that is being fired, once the framework successfully saves the record in the database.
It seems like force:recordSaveSuccess
event in not handled in home page, well handling the toast event force:showToast
might work for your case.
<aura:component implements="force:appHostable" >
<! -- did not work for home page -->
<aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.viewRefreshed}"/>
<aura:handler event="force:showToast" action="{! c.viewRefreshed}" />
<aura:dependency resource="markup://force:editRecord" type="EVENT" />
<c:SLDSButton label="Edit Account" onclick="{! c.editAccount }" />
</aura:component>
But if you need a bit more control over the actions like cancel,save then use <force:editRecord />
in your custom slds modal and wire up your own custom cancel and save button actions.
Eg:
component:
<aura:component>
<aura:attribute name="recordId" type="String" default="a02D0000006V8Ni"/>
<aura:attribute name="saveState" type="String" default="UNSAVED" />
<aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.handleSaveSuccess}"/>
<c:sldsModal aura:id="modal">
<force:recordEdit aura:id="edit" recordId="{!v.recordId}" />
<ui:button label="Save" press="{!c.save}"/>
<ui:button label="Cancel" press="{!c.cancel}"/>
</c:sldsmodal>
</aura:component>
controller.js:
({
save : function(cmp, event) {
// Save the record
cmp.find("edit").get("e.recordSave").fire();
},
handleSaveSuccess : function(cmp, event) {
// get called once save is done
},
cancel : function(cmp, event) {
// hide the slds modal
},
})
Lightning starts loading components well after the DOMContentLoaded phase, so any methods that you call (jQuery or otherwise) that depend on this state will execute immediately instead of being placed in the asynchronous event queue. Lightning itself starts running after DOMContentLoaded itself, in fact, because it has to wait until it is fully loaded before it can run. Whatever you're trying to do, you'll want to place your code in the afterScriptsLoaded handler of ltng:require.
Best Answer
If you need to wait until after the DOM is available, then you should use a renderer.
The afterRender event fires after the DOM is ready. You can then use this to assign values, modify DOM.
First you will need a function in your lightning component's helper:
Second you need to have to call this from the renderer:
Normally you don't want to use renderers for arbitrary assigning values as this is what the attribute binding is intended to accomplish. But in this case where you are dynamically assigning which fields will even be present based on object...this sounds like a good use case.