Checkbox Class

Form input that can be either checked or unchecked. The input consists of a square box with a checkmark when selected.
Here's a simple example of how to instantiate a checkbox using an existing div (DOM element) and a minimal config. See config settings for a full range of options.
    var checkbox = new javaxt.dhtml.Checkbox(div, {
        label: "I Agree",
        checked: false
    });
  
Once the checkbox is instantiated you can call any of the public methods. You can also add event listeners by overriding any of the public "on" or "before" methods like this:
    checkbox.onClick = function(checked){
        console.log("I Agree", checked);
    };
 

Constructors

Checkbox( parent, config )
Used to instantiate this class
parentDOM element in which to render this component
configConfiguration settings (optional). See config options for more information.

Config Options

label
Label for the checkbox (optional). Accepts either a string or a DOM element.
value
Value associated with the checkbox (optional). Note that this is different than the checkbox state. Use the isChecked() method to determine whether the checkbox is checked.
checked
If true, the checkbox will initially render with a check. Default is false.
disabled
If true, the component will be disabled when rendered. Default is false.
style
Style for individual elements within the component. Note that you can provide CSS class names instead of individual style definitions.

Events

onClick( checked )
Called whenever the checkbox is clicked.
onChange( checked )
Called whenever the checkbox value is changed.

Public Methods

enable( )
Used to enable the checkbox.
disable( )
Used to disable the checkbox.
select( silent )
Used to add a check to the checkbox.
deselect( silent )
Used to remove the check from the checkbox.
toggle( )
Used to toggle the checkbox state.
getValue( )
Returns the value associated with the checkbox. Note that this is different than the checkbox state. Use the isChecked() method to determine whether the checkbox is checked. The value is defined in the config used to instantiate this class.
isChecked( )
Returns true if the checkbox is checked.