Mendix Client 5 API Documentation


mxui.widget._WidgetBase

mxui.widget._WidgetBase is the object all widgets must inherit of. It inherits from dijit._WidgetBase, which serves as a foundation for all widgets. For more information on Dijit widgets and their lifecycle see the widget lifecycle documentation.

Attributes

Widget attributes should be accessed using their attribute functions: _WidgetBase.set and _WidgetBase.get.

mxid

The unique id for the widget.

Example

"54015330-4ce4-4346-8d0a-1ff92bfb5c99"

mxform

A reference to the containing form, see mxui.lib.Form.

mxcontext

The current context, see mendix.lib.MxContext.

suspended

Whether the widget is suspended. Suspended widgets do not update themselves.

disabled

Whether the widget is disabled. Disabled widgets do not allow editing.

doParse

Whether the widget should be parsed. If set to false it is responsible for parsing its own content.

Abstract methods

update(obj, callback)

Implement this method to handle setting of the current track object in the widget’s context.

Parameters

Name Type Description
obj MxObject The current track object or null if there is none.
callback Function Function to be called when finished.

resume()

Implement this method to do something when the widget is resumed.

suspend()

Implement this method to do something when the widget is suspended.

enable()

Implement this method to do something when the widget is enabled.

disable()

Implement this method to do something when the widget is disabled.

uninitialize()

Implement this method to release any resources you may have claimed for this widget.

Methods

parseContent(node, params)

Instantiates all widgets at or under node, passing the given parameters. If the widget’s doparse attribute is false, no widgets are instantiated. Only div nodes are considered.

Parameters

Name Type Description
node DOMNode The root for node to start parsing.
params Objects Parameters that will be mixed in with each instantiated widget.

Returns

Type Description
Array The instantiated widgets.

getChildren(nested)

Retrieve child widgets.

Parameters

Name Type Description
nested Boolean Whether to only retrieve direct children, or all children recursively.

Returns

Type Description
Array The requested child widgets.

Example

lv = dijit.byId("mxui_widget_ListView_0");
lv.getChildren().length; // number of direct children
lv.getChildren(true).length; // number of all children, their children, etc.

applyContext(context, callback)

Apply a context to the widget.

Parameters

Name Type Description
context MxContext The context to apply.
callback Function Function to be called when finished. It is run in the widget’s scope.

Example

// Passing a new, empty context to a widget.
widget.applyContext(new mendix.lib.MxContext(), function() {
    console.log("Done applying context to the widget.");
});

passContext(widgets, context, callback)

Distribute context to a list of widgets. This will invoke applyContext on all widgets in the list. If any of the widgets do not implement applyContext (e.g. standard Dijit widgets), context is passed to its seperate child widgets.

Parameters

Name Type Description
widgets Array The list of widgets to apply context to.
context MxContext Optional. If not given, the current context of the widget will be used.
callback Function Function to be called when finished.

subscribe(sub)

Alias of mx.data.subscribe, but it also checks for redundant subscribes, and automatically removes all subscribes when the widget gets destroyed.

unsubscribe(handler)

Alias of mx.data.unsubscribe.

listen(message, callback)

Alias of mxui.lib.Form.listen, but it also automatically removes all listeners when the widget gets destroyed.

unlisten(handler)

Alias of mxui.lib.Form.unlisten.

collect(chain, callback)

Alias of mendix.lang.collect, but it automatically uses the widget’s scope.

sequence(chain, callback)

Alias of mendix.lang.sequence, but it automatically uses the widget’s scope.

addOnLoad(handler)

Add a function to be called when the widget is loaded.

Parameters

Name Type Description
handler Function Function to be called when the widget is loaded.

Example

myWidget.addOnLoad(function() {
    console.log("myWidget was loaded");
});

addOnDestroy(handler)

Add a function to be called when the widget gets destroyed.

Parameters

Name Type Description
handler Function Function to be called when the widget gets destroyed.

Example

myWidget.addOnDestroy(function() {
    console.log("cleanup widget");
});

destroy()

Destroy the widget. Do not overwrite this method, use the uninitialize method for widget cleanup.

myWidget.destroy(); // Free any resources associated with this widget.