How to run a function after a Custom Mendix Widget loads & renders

0
Hello! I'm trying to run a function after a mendix widget loads but i'm having trouble accessing an appropriate callback function. Before i was trying this with a custom widget, I was using the below snippet (Appendix B) to successfully run JS after a ListView finished loading & rendering, but the same does not work for a widget.   The callback classes & properties that seem to be available to me are listed below (Appendix A). I've tried a few of them (swapping out _onLoad for _loaded, _rendered, etc) but nothing has worked so far. Any help would be appreciated, thank you     Appendix A   Appendix B var selector; selector = dijit.registry.byNode(this.domNode.previousSibling); if (typeof selector === "undefined") { selector = dijit.registry.byNode(this.domNode.previousSibling.children[1]); } console.log(selector); dojo.require("dojo.aspect"); dojo.aspect.after(selector, "_onLoad", function(deferred){ console.log("jqx loaded"); return deferred; });  
asked
3 answers
1

To others: Dillon is trying to attach a function to run after just one specific widget is done loading. While trying to run a function after the whole page is loaded is challenging, just doing it after 1 widget isn't as tough.

Dillon, since it's your own widget that you're trying to tie into, can you not add an empty function called "onWidgetRendered" that gets called wherever your widget is actually done the dom rendering?

Once you had that, you could use aspect.after to attach your custom function.

answered
0

You are not the first one looking for this, and there is no easy answer:

  1. The order of the rendering of the widgets on the page is not determined and can not be influenced
  2. The Dojo.AddOnLoad is no solution
  3. I have never used the dojo.aspect '_onload'. Probably those events are private.
  4. You can not call load, that would be impossible or create an infinite loop.

 

Suggestions:

  1. Use a htmls/java snippet widget and paste your code in there. That is executed quite late in the loading process. Optionally with a delay or a limited loop that waits for the div to appear.
  2. Use a widget a listens to an attribute for a change and start your code from that moment. This approach needs a refresh in a microflow. But
  3. Take a look at domReady but notice the ready() part in case of widgets. All mendix widgets use require

 

The only things that worked for me where:

  1. Microflowtimer on the page with a 1000 msec delay that does the job, very ugly, causes screen flickering
answered
0

For this specific thing I created some Javascript widget a lot like the HTML snippet in which I recursively call a function until some object is found on the page. After it is found it quits the loop and triggers the callback function.

To be sure the loop is not endless when the object is never found, I added a parameter to call it a fixed amount of times and if within this time it is not found (lets say 10 seconds) also end the loop and don't trigger the callback function.

So, actually, option 1 that Chris is mentioning would be a go for your problem.

answered