Widget that is used to indicate and change the status of other widgets.
Table of contents
In CP, you can embed the widget only into the header of an aps/ActiveItem container.
For UX1, find the nested rules for this widget in the recommended Widget Hierarchy.
If you want to enable users to switch a plain widget or a widget container to the on/off or enable/disable status,
an effective way is to use the aps/Switch
widget. Customizing its onClick
handler, you can influence the above mentioned
widgets.
The status
property of the aps/Switch
widget allows you to display 3 different static statuses:
on
off
failed to switch
Additionally, it can indicate two intermediate statuses:
enabling
disabling
A user can toggle the statical status (on/off) of the widget by clicking on the widget.
In the JS code, you can analyze the status
property and define the status mapping to its visualization
by means of the statusInfo
set:
status
- reflects the current status with the following possible values:
on
off - default value
disabling
offByError
enabling
statusInfo
- defines a label for each status. Default values are as follows:
statusInfo: {
on: {
label: "ON"
},
disabling: {
label: "OFF"
},
off: {
label: "OFF"
},
offByError: {
label: "OFF"
},
enabling: {
label: "ON"
}
}
The rules of transition between statuses are defined in the onClick
method.
You can redefine it as in the following example.
require(["aps/load", "aps/ready!"],
function(load) {
load(["aps/Panel", [
["aps/FieldSet", [
["aps/Switch", {
onClick: function(){
var self = this;
switch(this.status){
case "on":
this.set("status", "disabling");
setTimeout(function(){ self.set("status", "off"); }, 700);
break;
case "disabling":
break;
case "off":
this.set("status", "enabling");
setTimeout(function(){ self.set("status", "on"); }, 700);
break;
case "offByError":
this.set("status", "enabling");
setTimeout(function(){ self.set("status", "on"); }, 700);
break;
case "enabling":
break;
}
}
}]]]]]);
});
PROPERTY |
TYPE |
DEFAULT |
DESCRIPTION |
---|---|---|---|
boolean |
false |
Specifies if the widget will respond to user input. |
|
string |
undefined |
This specifies the widget width that is relevant only for widgets inside Container, FieldSet, or Tiles. |
|
boolean |
false |
If the widget is busy then this property is true. |
|
string |
“” |
Text that is shown as a label if the widget is placed inside a aps/FieldSet. |
|
string |
off |
Reflects the current status. |
|
object |
{}} |
Describes statuses. |
|
boolean |
true |
If this property value is set to true, then the widget is visible. |
This specifies the widget width that is relevant only for widgets inside Container, FieldSet, or Tiles. In other cases it will be ignored.
gridSize string contains few options with number values (from 1 to 12) separated by spaces, which specify the grid size of the widget in different layouts:
- md - desktop
- xs - phone
For example, gridSize: “md-4 xs-2”.
All values below 1, e.g. “md-0”, will be replaced with the empty string (“”), values above 12, e.g. “md-14”, will be reduced to 12 (“md-12”).
Default value: undefined.
Text that is shown as a label if the widget is placed inside a aps/FieldSet.
Default value: “”.
Reflects the current status. Possible values are: on, off, disabling, offByError, enabling. Default value: “off”.
Describes statuses. For instance, statusInfo.on.label is a text displayed when the current status is “on”. Default value: {}}.
If this property value is set to true, then the widget is visible.
Default value: true.
METHOD |
RETURN |
DESCRIPTION |
---|---|---|
object
|
Sets the isBusy property to false |
|
undefined
|
Destroys this widget |
|
any
|
Get a property of the Stateful instance |
|
array
|
Discover and return all parents of the widget |
|
dijit/_widgetbase
function
|
Place this widget somewhere in the DOM based on standard dojo/dom-construct::place() conventions |
|
object
function
|
Set a property of the Stateful instance |
|
undefined
|
Gets started after the DOM fragment is added to the document |
Destroys this widget. Will also destroy any resources (including widgets) registered via this.own(). This method will also destroy internal widgets such as those created from a template.
Return: undefined
Get a property of the Stateful instance. Get a named property of the Stateful object. The property may potentially be retrieved via a getter method in subclasses.
In the base class, this just retrieves the object’s property.
Return: any
Place this widget somewhere in the DOM based on standard dojo/dom-construct::place() conventions. A convenience function providing a simple shorthand mechanism to put an existing (or newly created) widget somewhere in the DOM, and allow chaining.
Return: dijit/_widgetbase function
Set a property of the Stateful instance. Sets named properties of the stateful object and notifies the watchers of the property. A programmatic setter may be defined in subclasses.
Return: object function
Gets started after the DOM fragment is added to the document Called after the widget and its children have been created and added to the page, and all related widgets have finished their create() cycle, up through postCreate().
Note that startup() may be called while the widget is still hidden, for example if the widget is inside a hidden dijit/Dialog or an unselected tab of a dijit/layout/TabContainer. For widgets that need to do layout, it’s best to put that layout code inside resize(), and then extend dijit/layout/_LayoutWidget so that resize() is called when the widget is visible.
Return: undefined
EVENT |
RETURN |
DESCRIPTION |
---|---|---|
undefined
|
The method is called when a user clicks on the widget |
The method is called when a user clicks on the widget.