Work with Toolbar
Setting/getting values and states
Setting values/states
You can change the value or state (for a TwoState navItem) of a control with the help of the setState() method. It takes one parameter: a key-value pair with the ID of the control and its new value (state).
Here is how you can use it to change the state of a TwoState navItem:
{type:"navItem", twoState:true, id:"check"}
...
toolbar.setState({"check":true});
//or
toolbar.setState({"check":false});
And this is how you can change the value of an input:
{type:"input", id:"name", value:""}
...
toolbar.setState({"name":"Maintenance"});
Related sample: Toolbar. Set state
Getting values/states
To get the current value of the control, use the getState() method.
Starting from v7.0, the method can take the id of a Toolbar control as a parameter and return the value/state of the control. If id is not specified, the method returns an object with IDs of controls and their values/states.
This is what the method returns for a TwoState navItem:
{type:"navItem", twoState:true, id:"check"}
...
toolbar.getState("check"); // -> true/false
// or
toolbar.getState(); // -> { "check":true } or { "check":false }
And this is a possible return value for an input:
{type:"input", id:"name", value:"Maintenance"}
...
toolbar.getState("name"); // -> "Maintenance"
// or
toolbar.getState(); // -> {"name":"Maintenance"}
Related sample: Toolbar. Get state
Hiding and showing controls
You can show or hide controls by their IDs. Pass them to the corresponding methods - show() and hide():
toolbar.hide(id); // hides a control
toolbar.show(id); // shows a control
Related sample: Toolbar. Hide / show items
Starting from v7.0, it is possible to hide/show all Toolbar controls on the page at once by using the methods without parameters:
// hides all Toolbar controls
toolbar.hide();
// shows all Toolbar controls
toolbar.show();
Disabling and enabling controls
You can disable or enable controls. The related methods - enable() and disable() - take the IDs of controls as parameters:
toolbar.disable(id); // disables a control
toolbar.enable(id); // enables a control
Related sample: Toolbar. Enable / disable items
Starting from v7.0, it is possible to disable/enable all Toolbar controls on the page at once by using the methods without parameters:
// disables all Toolbar controls
toolbar.disable();
// enables all Toolbar controls
toolbar.enable();
Checking if a Toolbar item is disabled
To check if an item of Toolbar is disabled, call the isDisabled() method. The method takes one parameter:
id | (string, number) an id of a toolbar item |
menu.isDisabled("1"); // -> true/false
Related sample: Toolbar. Enable / disable items
Adding a tooltip to a control
You can attach a tooltip to a control. For this you need to provide the tooltip property with the tooltip text in the control object before the toolbar initialization:
{
type: "text",
value: "test1",
tooltip: "tooltip for test1"
}