CustomControlModule

The interface implemented by custom control modules. The file is referenced using the "Module path" property of a Custom Control.

See Referencing module JavaScript for details. The module instance can be accessed using the instance member of a CustomControl.

For an explanation of when events are called, see Order of events.

See Communication between controls for examples of how instances of custom controls can communicate with each other.

To add a custom control directly to the toolbox, see Native Custom Controls.

Examples

Sample BasicControl.js

define( () => {
"use strict";

class BasicControl
{
	draw( oControlHost )
	{
		oControlHost.container.innerHTML = "Hello world";
	}
}

return BasicControl;
} );

Sample AdvancedControl.js

define( () => {
"use strict";

class AdvancedControl
{
	initialize( oControlHost, fnDoneInitializing )
	{
		fnDoneInitializing();
	}
	destroy( oControlHost )
	{

	}
	draw( oControlHost )
	{
		oControlHost.container.innerHTML = "Hello world";
	}
	show( oControlHost )
	{

	}
	hide( oControlHost )
	{

	}
	isInValidState( oControlHost )
	{

	}
	getParameters( oControlHost )
	{

	}
	setData( oControlHost, oDataStore )
	{

	}
}

return AdvancedControl;
} );

Methods

destroy(oControlHost)

The control is being destroyed so do any necessary cleanup. This method is optional.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

draw(oControlHost)

Draw the control. This method is optional if the control has no UI.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

Example
draw( oControlHost )
{
	oControlHost.container.innerHTML = "Hello world";
}

getParameters(oControlHost) → (nullable) {Array.<Parameter>|Array.<RangeParameter>}

Called by the ControlHost to get the current values to use for parameters fulfilled by the control. This method is optional.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

Returns:

An array of parameters.

Type: 
Array.<Parameter> | Array.<RangeParameter>
Example
getParameters( oControlHost )
{
	if ( this.m_sel.selectedIndex < 1 )
	{
		return null;
	}
	const { value } = this.m_sel.options[this.m_sel.selectedIndex];
	return [{
		"parameter": "parameter1",
		"values": [{ "use" : value }]
	}];
}

hide(oControlHost)

Called when the control is being hidden (not displayed). This method is optional.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

initialize(oControlHost, fnDoneInitializing) → {Promise}

Initialize the control. This method is optional. If this method is implemented, fnDoneInitializing must be called when done initializing, or a Promise must be returned.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

fnDoneInitializingfunction

The callback function to tell the control host when the initialization has completed.

Returns:

An optional promise that will be waited on instead of calling fnDoneInitializing. Since Version 6

Type: 
Promise
Example

Asynchronous initialization

initialize( oControlHost, fnDoneInitializing )
{
	require( ["Module"], this.dependenciesLoaded.bind( this, fnDoneInitializing ) )
}

dependenciesLoaded( fnDoneInitializing, oModule )
{
	fnDoneInitializing();
}

isInValidState(oControlHost) → {Boolean}

The valid state of the control. This method is optional. This is used to determine things like enabling "Next" and "Finish" prompt buttons.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

Returns:

true if the control is in a valid state and false otherwise.

Type: 
Boolean
Example
isInValidState( oControlHost )
{
	return this.m_sel.selectedIndex > 0;
}

setData(oControlHost, oDataStore)

Called to pass authored data into the control. This method is optional.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.

oDataStoreDataStore

The data as a data store.

Examples

Keep a single data store to use later in the draw function

setData( oControlHost, oDataStore )
{
	this.m_oDataStore = oDataStore;
}

Keep multiple data stores by index to use later in the draw function

setData( oControlHost, oDataStore )
{
	this.m_aDataStore[oDataStore.index] = oDataStore;
}

Keep multiple data stores by name to use later in the draw function

setData( oControlHost, oDataStore )
{
	this.m_oDataStores[oDataStore.name] = oDataStore;
}

show(oControlHost)

Called when the control is being shown (displayed). This method is optional.

Parameters:
NameTypeDescription
oControlHostControlHost

The control host.