Class: mxui/lib/form/_FormBase

mxui/lib/form/_FormBase

Forms are the client implementation of the Mendix Pages concept. They can be shown in content or as a (modal) popup.

This class contains the functionality shared between all Form types. This means that all of the following applies to _WidgetBase#mxform.

Constructor

new mxui/lib/form/_FormBase()

Constructs a new _FormBase.

Members

(readonly) domNode :HTMLElement

The form's document node.

Type:
  • HTMLElement

(readonly) id :string

Unique id of the form.

Type:
  • string

(readonly) path :string

Path to the form, e.g. MyFirstModule/EmployeeOverview_mobile.page.xml.

Type:
  • string

(readonly) title :string

Title of the form, as defined in the Modeler.

Type:
  • string

Methods

callRecursive(method, …param)

Invoke a function on all direct child widgets.

Parameters:
Name Type Attributes Description
method string

method to invoke on all top level children

param * <repeatable>

parameters to call the method with

Example
// Disable all child widgets of the form (you would normally use .enable() for this).
form.callRecursive("set", "disabled", true);

commit(function, error)

Shortcut for calling mxui/lib/form/_FormBase#publish with the commit message.

Parameters:
Name Type Description
function mxui/lib/form/_FormBase~SuccessCallback

to call after all listeners have finished

error mxui/lib/form/_FormBase~ErrorCallback

function to call in case of an error

getChildren(nested) → {Array.<dijit._WidgetBase>}

Retrieve child widgets of the form.

Parameters:
Name Type Description
nested boolean

retrieve all children recursively if true, only direct children otherwise

Returns:

child widgets of the form

Type
Array.<dijit._WidgetBase>
Example
mx.ui.openForm("MyFirstModule/Puppies.page.xml", {
    location: "popup",
    callback: function(form) {
        // List all direct child widgets in the popup.
        console.log(form.getChildren());

        // List all child widgets in the popup.
        console.log(form.getChildren(true));
    }
});

listen() → {mxui/lib/form/_FormBase~ListenHandle}

Register a listener to a given message.

A listener receives two parameters: callback and error. callback should be called on success, error on failure. Listeners are called in reverse order of which they were registered.

message {string} message to listen to callback {mxui/lib/form/_FormBase/ListenCallback} function to call when the message is broadcast

Tutorials:
Returns:

handle that can be used to remove the subscription using mxui/lib/form/_FormBase#unlisten

Type
mxui/lib/form/_FormBase~ListenHandle
Example
l = form.listen("validate", function(callback, error) {
    try {
        validateStuff();
        callback();
    } catch (e) {
        error(e);
    }
});

publish(message, callback, error)

Publish a message throughout the form, calling all listeners for it.

Listeners are called in reverse order of which they were registered.

Parameters:
Name Type Description
message string

message to publish

callback mxui/lib/form/_FormBase~SuccessCallback

function to call after all listeners have finished

error mxui/lib/form/_FormBase~ErrorCallback

function to call in case of an error

Tutorials:
Example
form.publish("save", function() {
    console.log("Called all listeners for the 'save' message.");
}, function(e) {
    console.log("Something went wrong during save:", e.message);
});

rollback(function, error)

Shortcut for calling mxui/lib/form/_FormBase#publish with the rollback message.

Parameters:
Name Type Description
function mxui/lib/form/_FormBase~SuccessCallback

to call after all listeners have finished

error mxui/lib/form/_FormBase~ErrorCallback

function to call in case of an error

save(function, error)

Shortcut for calling mxui/lib/form/_FormBase#publish with the save message.

Parameters:
Name Type Description
function mxui/lib/form/_FormBase~SuccessCallback

to call after all listeners have finished

error mxui/lib/form/_FormBase~ErrorCallback

function to call in case of an error

unlisten(handle)

Unregister a listener.

Parameters:
Name Type Description
handle mxui/lib/form/_FormBase~ListenHandle

of the listener to unregister

Tutorials:
Example
l = form.listen("rollback", function(callback, error) {
    rollbackStuff();
});

form.unlisten(l);

validate(function, error)

Shortcut for calling mxui/lib/form/_FormBase#publish with the validate message.

Parameters:
Name Type Description
function mxui/lib/form/_FormBase~SuccessCallback

to call after all listeners have finished

error mxui/lib/form/_FormBase~ErrorCallback

function to call in case of an error

Type Definitions

ErrorCallback(error)

Function to call when a listener encounters an error.

Parameters:
Name Type Description
error Error

error object indicating the reason of the error

ListenCallback(callback, error)

Callback for handling a message that the form listens to.

Parameters:
Name Type Description
callback mxui/lib/form/_FormBase~SuccessCallback
error mxui/lib/form/_FormBase~ErrorCallback

ListenHandle

Handle of a listener.

SuccessCallback()

Function to call when a listener finishes successfully.

Events

onAfterHide

Called after the form is hidden.

This method is intended to be connected to using dojo/aspect.after.

onAfterShow

Called after the form is shown.

This method is intended to be connected to using dojo/aspect.after.

onBeforeHide

Called before the form is hidden.

This method is intended to be connected to using dojo/aspect.after.

onBeforeShow

Called before the form is shown.

This method is intended to be connected to using dojo/aspect.after.