67
Views
1
Comments
Solved
Why is the Event Listener added on the OnRender event instead of OnReady Event
Question

On the Front End Practice test on the Outsystems training this question is posed

My question is why is the answer the OnRender and not OnReady, but on the documentation i thought it said we are to add Event Listeners OnReady

2022-06-07 11-25-18
DiogoRomero
Solution

Hi @Isaac Wangombe ,

Great point I don't think this answer is correct at least not with the "OnRender" event only. The on Ready event handler runs when the Screen or Block is ready, i.e. when the DOM is ready which makes this the ideal place to: 

  • Initialize a third-party component that needs the DOM.
  • Add listeners to a DOM element.
  • Set the focus on an input widget.
  • Add listeners to the JavaScript window object.


The on render can have the exact same use cases but also extra ones like acting on data changes since this event can be triggered multiple times while the On Ready can't. According to best practices the best place should be during the "On Ready" event because even though it should work during the "On Render", in my perspective, you don't want to keep spamming the same event listener logic every time there is a data change or worst build custom logic to avoid it. So I am with you, that answer is not the appropriate one.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.