0

I have a simple component that just pops up a browser alert if a specific field is filled in when the page finishes rendering. I'm not too familiar with the different DOM events and when they fire, but I am using render since load gave me an error. My hope is that I can just have the alert pop up when the page finishes loading, but not after every save. Is there a DOM event that would capture that? Or is there another good way to handle this?

<aura:handler name="render" value="{!this}" action="{!c.onRender}"/>
onRender : function(cmp, event) {
        var myAccount = cmp.get("v.acc");

        if(myAccount.Alert__c != null)
        {
            alert(myAccount.Alert__c);
        }
    }

1 Answer 1

1

If you are looking for firing it just once, You can keep a boolean property to check if page has loaded. Refer the property inside the onRender function to execute your code just once.

<aura:attribute name="showAlert" type="Boolean" /> 
<aura:handler name="render" value="{!this}" action="{!c.onRender}"/>

onRender : function(cmp, event) {
     var myAccount = cmp.get("v.acc");
     var showalert = cmp.get("v.showAlert");
     if(myAccount.Alert__c != null && !showalert)
     {
        cmp.set("v.showAlert", true);
        alert(myAccount.Alert__c);
     }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.