How to use dojo.aspect.after in relation to Mendix form events (onAfterShow)

2
In the context of a custom widget I tried: dojo.aspect.after(mxui.lib.form._FormBase.prototype, "onAfterShow", function(){ alert('onaftershow form'); }); and dojo.aspect.after(mxui.lib.form._FormBase, "onAfterShow", function(){ alert('onaftershow form'); }); and dojo.aspect.after(this.mxform, "onAfterShow", function(){ alert('onaftershow form'); }); All this didn't work. I found some old code on the form, but that didn't work either.
asked
2 answers
1

Hi Herbert,

This a part of my code in the data grid extension. Could be that aspect is not loaded, than you need to require it.

Not sure; but think that you can only place aspect account a instantiated object and not a prototype.

require(["dojo/aspect", "dojo/_base/lang"], function( aspect, lang) {
    aspect.after(this.grid, "fillGrid", lang.hitch(this, this.updateEmptyTable));
});

https://github.com/Andries-Smit/DataGridExtention/src/DataGridExtension/widget/EmptyTable.js#L31

Alternatively you could go back to old school dojo with dojo/_base/connect

var handle = dojo.connect(myInstance, "execute", callback);
...
dojo.disconnect(handle);
answered
0

I hate digging up old threads, but I felt I should include this info here for others (like me) who found this question via search:

In Mendix 6, there is a function called onNavigation on mxui/lib/form/ContentForm that you can use to catch page transitions. The onBeforeShow, onAfterShow, onBeforeHide, and onAfterHide functions don't get called anymore. I think this is because Mendix doesn't completely unload and reload forms anymore - instead it replaces the content that is necessary, keeping layouts intact.

So, something like this works for me on Mendix 6.5.1:

aspect.after(this.mxform, "onNavigation", function(){
        alert('navigation occurred');
});

I will file a ticket to update documentation accordingly.

answered