aps/CheckBox

Same as an HTML checkbox, but with fancy styling.

Compatibility

All user panels - CP and UX1

Overview

aps/CheckBox is a modified analog of the HTML checkbox element.

In addition to the standard properties of the HTML element, such as value, checked, and disabled, the widget may have supplemental text (the hint property), a description (description), a name for displaying in FieldSet (label or title). It may also have child widgets from the input category.

Find the nested rules for this widget in the recommended Widget Hierarchy.

Examples

The first two examples demonstrate three different declaration methods. The other examples illustrate some use cases including synchronization with a model.

Widget Loader

RUN DEMO

require(["aps/load", "aps/ready!"],
    function(load){
        "use strict";
        load(["aps/PageContainer", [
            ["aps/Panel", [
                ["aps/FieldSet", [
                    ["aps/CheckBox", {
                        value: "loader",
                        description: "I'm CheckBox"
                    }]
            ]]]]
        ]]);
    });

Widget Constructor

RUN DEMO

require(["aps/CheckBox", "aps/Panel", "aps/FieldSet", "aps/PageContainer", "aps/ready!"],
  function(CheckBox, Panel, FieldSet, PageContainer){
    var page = new PageContainer({}, "simpleCheckBox");
    var panel = new Panel();
    var fieldSet = new FieldSet();
    fieldSet.addChild(new CheckBox({
      value: "program",
      label: "I'm CheckBox"
    }));
    panel.addChild(fieldSet);
    page.addChild(panel);
    page.startup();
});

Syncing with Model

RUN DEMO

require(["aps/load", "dojox/mvc/getStateful", "dojox/mvc/at", "aps/ready!"],
  	function(load, getStateful, at) {
       "use strict";
       var model = new getStateful({"checked": false});
       load(["aps/PageContainer", [
           ["aps/Panel", [
               ["aps/FieldSet", [
                   ["aps/CheckBox", {
                       label: "This is my CheckBox",
                       checked: at(model, 'checked')
                   }],
                   ["aps/Output", {
                       content: "My CheckBox is ${val} :-)",
                       val: at(model, 'checked')
                   }]

               ]]
           ]]
       ]]);
	});

Multi-Layer Structure

RUN DEMO

require(["aps/load", "aps/ready!"],
  function(load){
    "use strict";
    load(["aps/PageContainer", [
       [ "aps/FieldSet", { title: "Complex example" },
          [[ "aps/Container", { label: "Country" }, [
            [ "aps/Select", {
                options: [{
                  label: "United States",
                  value: "United States",
                  selected: true
                }]
            }],
            [ "aps/CheckBox",  { description: "Change date and time" },[
              [ "aps/Container", [[ "aps/TextBox", { value: "22" } ]]],
              [ "aps/Container", [[ "aps/TextBox", { value: "21" } ]]]
            ]]
    ]]]]]]);
});

CheckBox as a Parent

RUN DEMO

require(['dijit/registry', 'aps/load', 'aps/ready!'],
    function(registry, load) {
        load(["aps/Panel", [
            ["aps/FieldSet", [
                ["aps/CheckBox", {
                    id: "msg2",
                    gridSize: "md-6 xs-12",
                    description: "flowers-store.com",
                    onClick: function() {
                        if (this.get('checked')) {
                            registry.byId('sub-2').set('visible', true);
                            registry.byId('2year').set('disabled', false);
                        } else {
                            registry.byId('sub-2').set('visible', false);
                            registry.byId('2year').set('disabled', true);
                        }
                    }
                },
                [
                     ["aps/Select", {
                         id: '2year',
                         disabled: true,
                         options: [{
                             label: "1 Year ($10.00/year)",
                             value: "1",
                             selected: true
                         }, {
                             label: "2 Year ($7.00/year)",
                             value: "2"
                         }]
                     }],
                     ["aps/FieldSet", {
                            id: "sub-2",
                            visible: false
                        },
                         [
                             ["aps/CheckBox", {
                                 gridSize: "md-12 xs-12",
                                 label: "Technical Contact",
                                 description: " Same as the registrant contact"
                             }],
                             ["aps/CheckBox", {
                                 gridSize: "md-12 xs-12",
                                 label: "Billing Contact",
                                 description: "Same as the registrant contact"
                             }],
                             ["aps/Select", {
                                 gridSize: "md-12 xs-12",
                                 label: "Registrant Contact Type",
                                 options: [{
                                     label: "Company",
                                     value: "company",
                                     selected: true
                                 }, {
                                     label: "Individual",
                                     value: "ind"
                                 }]
                             }],
                             ["aps/TextBox", {
                                 gridSize: "md-12 xs-12",
                                 label: "Registrant Identity Number",
                                 description: "Use the ID you registered during signup."
                             }]
                         ]
                     ]
                ]
             ]
        ]]
    ]] );
});

Public Properties

PROPERTY

TYPE

DEFAULT

DESCRIPTION

autoSize

boolean

true

Only for PCP / CCP v1.

checked

string

false

If checkBox is checked, then “checked” or true.

description

string

“”

Textual description to be displayed as a small greyed text under the control.

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.

hint

string

“”

Help information in a widget.

isBusy

boolean

false

If the widget is busy then this property is true.

label

string

“”

Text that is shown as a label if the widget is placed inside a aps/FieldSet.

missingMessage

string

This value is required.

The message to display if value is empty and the field is required.

optionalText

string

undefined

Text for optional widgets of the Input category.

placeHolder

string

“”

Grayed out initial string in a field.

required

boolean

false

User is required to enter data in the input field.

size

number

10 - PCP / CCP v1, undefined - CCP v2

Affects the selection of a CSS class that defines the width of the input field of the widget.

value

string

“”

The current value of a checkBox.

visible

boolean

true

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

autoSize boolean

Only for PCP / CCP v1. If this property value is set to “true”, then a CSS class is assigned to the widget based on the value of the “size” property: size <= 7 - f-small-size (40px) 7 < size <= 33 - f-middle-size (215px) 33 < size - f-big-size (240px) The default value of this property is true. If you want to use your own CSS class for defining the widget’s size, you should set this property value to “false” and specify your class name in the widget’s “class” property. Default value: true

checked string boolean

If checkBox is checked, then “checked” or true. Default value: false.

description string

Textual description to be displayed as a small greyed text under the control. Default value: “”.

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.

hint string

Help information in a widget. It is shown under the content of the widget. Deprecated in CCP v2. Default value: “”.

isBusy boolean

If the widget is busy then this property is true.

Default value: false.

label string

Text that is shown as a label if the widget is placed inside a aps/FieldSet.

Default value: “”.

missingMessage string

The message to display if value is empty and the field is required. The translated string value is read from the message file by default. Default value: “This value is required.”

optionalText string

Text for optional widgets of the Input category. Default value: undefined.

placeHolder string

Grayed out initial string in a field. For example, it can display instructions. Default value: “”.

required boolean

User is required to enter data in the input field. Default value: false.

size number

Affects the selection of a CSS class that defines the width of the input field of the widget.

size <= 7        f-small-size (40px)
7 < size <= 33   f-middle-size (215px)
size > 33        f-big-size (240px)

Default value: 10 - PCP / CCP v1, undefined - CCP v2.

value string

The current value of a checkBox. 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

addChild (child, insertIndex)

undefined

Makes the given widget a child of this widget

cancel ()

object

Sets the isBusy property to false

destroy ()

undefined

Destroys this widget, but not its descendants

extraValidator ()

boolean

Here, you can do additional verifications

focus ()

aps/checkbox
function

Focusing on the focusNode of the current object

get ()

any

Get a property of the Stateful instance

getChildren ()

array

Returns all direct children of this widget, i

getCustomErrorMessage ()

string

Here, you can return a custom error message

getParents ()

array

Discover and return all parents of the widget

placeAt ()

dijit/_widgetbase
function

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

removeAll ()

undefined

Remove all children in the widget

removeChild (widget)

undefined

Removes the passed widget instance from this widget and destroys it

reset ()

undefined

Resets the widget

set ()

object
function

Set a property of the Stateful instance

startup ()

undefined

Processing after the DOM fragment is added to the document

validate ()

boolean

Called by oninit, onblur, and onkeypress

addChild

Makes the given widget a child of this widget. Inserts specified child widget’s dom node as a child of this widget’s container node, and possibly does other processing (such as layout).

Return: undefined

ARGUMENT

TYPE

DESCRIPTION

child

Widget

Child widget

insertIndex

Number
String

Position child in the parent widget

cancel

Sets the isBusy property to false.

Return: object

destroy

Destroys this widget, but not its descendants. Descendants are the widgets inside this.containerNode. Will also destroy any resources (including widgets) registered via this.own().

Return: undefined

extraValidator

Here, you can do additional verifications.

Return: boolean

focus

Focusing on the focusNode of the current object

Return: aps/checkbox function

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

getChildren

Returns all direct children of this widget, i.e. all widgets underneath this.containerNode whose parent is this widget. Note that it returns not all descendetns, but only the direct children. Analogous to Node.childNodes, except containing widgets rather than DOMNodes.

The result intentionally excludes internally created widgets (a.k.a. supporting widgets) outside of this.containerNode.

Note the returned array is a simple array. The application code should not assume existence of methods like forEach().

Return: array

getCustomErrorMessage

Here, you can return a custom error message. The method must return a value, only if additional verifications fail. To change standard error messages, use respective properties.

Return: string

getParents

Discover and return all parents of the widget.

Return: array

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

removeAll

Remove all children in the widget.

Return: undefined

removeChild

Removes the passed widget instance from this widget and destroys it. You can also pass in an integer indicating the index within the container to remove (ie, removeChild(5) removes the sixth widget).

Return: undefined

ARGUMENT

TYPE

DESCRIPTION

widget

Widget
Int

Child widget or index

reset

Resets the widget.

Return: undefined

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

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

validate

Called by oninit, onblur, and onkeypress. Show missing or invalid messages if appropriate, and highlight textbox field.

Return: boolean

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.