aps/ToolbarButton

Button for a toolbar.

This widget should be used ONLY in an ``aps/Toolbar``. Find an example in aps/Toolbar.

Overview

Using the aps/ToolbarButton widget, you can display a toolbar button that contains the same properties and methods as the aps/Button widget.

Since all properties are the same as in aps/Button, below are just few examples for the aps/ToolbarButton. Examples of aps/Toolbar are presented later.

Button Label and Icon

To assign a label and an icon to a button, use the following properties:

  • label (preferable) or title - defines a text displayed on the button. Use only one of them.

  • iconClass or iconName - defines an icon for the button:

    • iconClass specifies a CSS class

      RUN DEMO

      require(["aps/Toolbar", "aps/ToolbarButton", "aps/PageContainer", "aps/ready!"],
        function(Toolbar, ToolbarButton, PageContainer){
          "use strict";
      
          var page = new PageContainer({}, "example");
      
          var toolbar = new Toolbar({});
      
          toolbar.addChild(new ToolbarButton({
            label:      "Add New Server",
            iconClass:  "sb-add-new-server"
          }));
      
          page.addChild(toolbar);
      
          page.startup();
      });
      
    • iconName specifies a path to the icon file

On Click Handler

You can add an on-click handler for a button by defining the onClick property:

RUN DEMO

require(["aps/Toolbar", "aps/ToolbarButton", "aps/PageContainer", "aps/ready!"],
  function(Toolbar, ToolbarButton, PageContainer){
    "use strict";

    var page = new PageContainer({}, "example");
    var toolbar = new Toolbar();

    toolbar.addChild(new ToolbarButton({
      label:      "Add New Server",
      iconClass:  "sb-add-new-server",
      onClick: function(){
        alert("triam!");
      }
    }));

    page.addChild(toolbar);

    page.startup();
});

After creating a button, irrespective of the way it was declared, you can specify an on-click handler at any time you like by using the on method with a value of the first argument set to “click”. You can get a button object with help of a dijit/registry object as explained at Base Properties and Methods.

RUN DEMO

require([
  "aps/Toolbar",
  "aps/ToolbarButton",
  "dijit/registry",
  "aps/PageContainer",
  "aps/ready!"
], function(Toolbar, ToolbarButton, registry, PageContainer){
  "use strict";

  var page = new PageContainer({}, "example");

  var toolbar = new Toolbar();

  toolbar.addChild(new ToolbarButton({
    id:         "AddNewServer",
    label:      "Add New Server",
    iconClass:  "sb-add-new-server"
  }));

  page.addChild(toolbar);

  page.startup();

  registry.byId("AddNewServer").on("click", function(e) {
    alert("click!");
  });
});

Public Properties

PROPERTY

TYPE

DEFAULT

DESCRIPTION

autoBusy

boolean

true

If true than a button will be disabled after a click.

busyLabel

string

Please wait

Text displayed while a button is disabled.

disabled

boolean

false

Specifies if the widget will respond to user input.

gridSize

string

undefined

This specifies the widget width that is relevant only for widgets inside Container, FieldSet, or Tiles.

hideFor

string

“”

It is a string containing “md” (hides the property in desktops), or “xs” (hides it in mobiles), or both “md xs” (hides the property regardless of the mode).

iconClass

string

“”

Class to apply to the DOMNode in a button to make it display an icon.

iconName

string

“”

Icon source - address to an icon file.

isBusy

boolean

false

If the widget is busy then this property is true.

label

string

“”

Text on the button.

requireItems

boolean

false

If “true” the button will be enabled only if ONE or MORE items in the aps/Grid is selected.

requireSingleItem

boolean

false

If “true” the button will be enabled only if ONE item in the aps/Grid is selected.

timeout

number

0

If exists, then it will call the cancel() method to enable the button after a period of time specified by this property.

title

string

“”

Text on the button.

visible

boolean

true

If this property value is set to true, then the widget is visible.

autoBusy boolean

If true than a button will be disabled after a click. Default value: true.

busyLabel string

Text displayed while a button is disabled. Default value: “Please wait” (PCP / CCP v1) or “Loading” (CCP v2).

disabled boolean

Specifies if the widget will respond to user input.

Default value: false.

gridSize string

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.

hideFor string

It is a string containing “md” (hides the property in desktops), or “xs” (hides it in mobiles), or both “md xs” (hides the property regardless of the mode). Default value: “”.

iconClass string

Class to apply to the DOMNode in a button to make it display an icon. Default value: “”.

iconName string

Icon source - address to an icon file. It has no effect without the label or title property. Only for CCP v1. Default value: “”.

isBusy boolean

If the widget is busy then this property is true.

Default value: false.

label string

Text on the button. You shouldn’t use both together. The preferred equivalent for the “title” property. Default value: “”.

requireItems boolean

If “true” the button will be enabled only if ONE or MORE items in the aps/Grid is selected. Default value: false.

requireSingleItem boolean

If “true” the button will be enabled only if ONE item in the aps/Grid is selected. This property has a priority on requireItems property. Default value: false.

timeout number

If exists, then it will call the cancel() method to enable the button after a period of time specified by this property. Default value: 0.

title string

Text on the button. Equivalent for the “title” property. You shouldn’t use both together. We recommended using the “label” property. Default value: “”.

visible boolean

If this property value is set to true, then the widget is visible.

Default value: true.

Public Methods

METHOD

RETURN

DESCRIPTION

cancel ()

undefined

Switches the button back to the enabled state

destroy ()

undefined

Destroys the button

get ()

any

Get a property of the Stateful instance

getParents ()

array

Discover and return all parents of the widget

makeBusy ()

aps.button
function

Does a transition between the ‘ready to handle user event’ (isBusy: false) state and the ‘busy’ (isBusy: true) state

placeAt ()

dijit/_widgetbase
function

Place this widget somewhere in the DOM based on standard dojo/dom-construct::place() conventions

resetTimeout (timeout)

undefined

Resets existing timeout and sets a new timeout

set ()

object
function

Set a property of the Stateful instance

setLabel (val)

undefined

Deprecated

startup ()

undefined

Processing after the DOM fragment is added to the document

cancel

Switches the button back to the enabled state. To prevent double submission by a user, aps.Button is switched to the disabled state automatically each time after the user clicks. To switch the button back to the enabled state, call the cancel() method in your onClick handler. Functionality is almost the same as dojox/form/BusyButton.

Return: undefined

destroy

Destroys the button.

Return: undefined

get

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

getParents

Discover and return all parents of the widget.

Return: array

makeBusy

Does a transition between the ‘ready to handle user event’ (isBusy: false) state and the ‘busy’ (isBusy: true) state. Also disables the button (disabled:true).

Return: aps.button function

placeAt

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

resetTimeout

Resets existing timeout and sets a new timeout.

Return: undefined

ARGUMENT

TYPE

DESCRIPTION

timeout

Int

Time in millisecondsю

set

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

setLabel

Deprecated. Use set() instead.

Return: undefined

ARGUMENT

TYPE

DESCRIPTION

val

String

The label of the button.

startup

Processing after the DOM fragment is added to the document. Called after a widget and its children have been created and added to the page and all related widgets have finished their creation cycle, that is after the postCreate() function is successfully completed for each of the related widgets. Note that startup() may be called while the widget is still hidden.

Return: undefined

Public Events

EVENT

RETURN

DESCRIPTION

onClick ()

undefined

The method is called when a user clicks on the widget

onClick

The method is called when a user clicks on the widget.