Question Arcady Goldmints-Orlov · Nov 23, 2016

Zen client methods and inheritance

I have a Zen page, and I would like to have an onload handler to run a bit of javascript when the page is ready. Unfortunately, the page inherits from a template, and the template already has an onload handler that does all kinds of useful things. Is there any way to override the onload handler in my page, while still being able to call the onload handler that is inherited from the template? In ObjectScript, there is ##super, but in javascript, there is no equivalent of that.

Comments

Alok Saldanha · Nov 23, 2016

This is more of a workaround than an answer, but could you change the onload handler in the superclass to call a single method, and call the same method in the unload handler of the subclass?

0
Timothy Leavitt · Nov 28, 2016

The Zen equivalent of ##super for JS is invokeSuper. Typically you'd just use:

this.invokeSuper('nameOfMethod',arguments);

All Zen components (including pages) have this. Here's an example from %ZEN.Component.dataCombo:

///  Set the value of a named property.<br>
ClientMethod setProperty(property, value, value2) [ Language = javascript ]
{
    switch(property) {
    case 'itemCount':
        break;
    case 'parameters':
        // set value of parameter: note that value will
        // be 1-based, so we have to convert it.
        // changing parameter always forces a query execution,
        // even in snapshot mode.
        if ('' != value) {
            value = value - 1;
            if (this.parameters[value]) {
                if (this.parameters[value].value != value2) {
                    this.parameters[value].value = value2;
                    this.clearCache();
                }
            }
        }
        break;
    default:
        // dispatch
        return this.invokeSuper('setProperty',arguments);
        break;
    }

    return true;
}
0