How do I override Dijit Methods in Mendix framework

5
Normally when I want to override a Widget's method, but still call the superclass' method in Dojo/Dijit terms, I would do something like this: Source code this.inherrited calls the superclass' method. The problems I have with this approach is that you can't use the dojo._base.declare method nor the normal require methods when defining Mendix widgets. Rather than list all the approaches that I've tried to solve this, I'll rather ask how do you create a first-rate Sub-class widget that still allows me to call the parent's method after overriding it? Essentially the scroll widget is not providing me with enough control over its behavior, so I need to override a private method in order to hook in new events.
asked
1 answers
3

interited doesn't work as it should indeed. What you can do is call the method on the superclass through apply:

dijit.form.HorizontalSlider._handleOnChange.apply(this, arguments)

This assumes the function is available and visible in the HorizontalSlider prototype.

Otherwise you could monkey patch the function in your constructor (post create) by keeping the original function in the closure of the new one:

function postCreate() {
  var original = this._handleOnChange;
  this._handleOnChange = dojo.hitch(this, function() {
    this.MyCustomChangeHandler(arguments); //your code
    return original.apply(this, arguments); 
  });

}
answered