Class: Checkbox

.ALS.Widgets. Checkbox


new Checkbox(id, label, callbackObject, callback)

Checkbox widget. Unchecked by default.

Parameters:
Name Type Description
id string

ID of this input. You can select this object using this ID.

label string

Label for this input. Pass locale property to localize the label.

callbackObject Object | L.ALS.Serializable

Object which contains callback. Just pass "this". If you plan to use serialization, this object MUST be instance of L.ALS.Serializable.

callback string

Name of the method of callbackObject that will be called when widget's value changes

Extends

Members


<protected> constructorArguments :Array.<any>

Contains arguments passed to this constructor

Type:
  • Array.<any>
Inherited From:

<protected> container :HTMLDivElement

Container of this widget

Type:
  • HTMLDivElement
Inherited From:

<protected> containerForRevertButton :Element

Container to place revert button to. Used by the settings.

Type:
  • Element
Inherited From:

<protected, readonly> customContainerClassName

Custom classname for a widget container.

Inherited From:

<protected, readonly> customWrapperClassName

Custom classname for an input wrapper. Alternative to setting classname at L.ALS.Widgets.BaseWidget#createContainer manually.

Inherited From:
Overrides:

<readonly> id

This widget's ID

Inherited From:

<protected> input :HTMLElement

Input element controlled by this widget

Type:
  • HTMLElement
Inherited From:

<protected> serializationIgnoreList :Array.<string>

Contains properties that won't be serialized. Append your properties at the constructor.

Type:
  • Array.<string>
Inherited From:

<readonly> undoable

Indicates whether this widget can revert back to its default value. If this widget is undoable, an undo button will be appended to it at settings window.

Inherited From:

wrapLabel

Indicates whether this widgets label should be wrapped when it's too wide. Wrapping might affect how your widget displays. Test it with both short labels and long labels.

Inherited From:
Overrides:

Methods


callCallback()

Calls callback attached to this widget

Warning: Callback will be called only when widget will be added to the widgetable! Util that all calls will be paused.

Inherited From:
Returns:
Type
VoidFunction

<protected> createContainer()

Creates container for this widget

Inherited From:
Returns:

Container for this widget

Type
HTMLDivElement

<protected> createInput()

Creates input element. If you're creating different element, override createInputElement() instead of this.

Inherited From:
Returns:

Input element

Type
HTMLElement

<protected> createInputElement()

Creates input element. You can also create non-input elements here.

Use it only to create input element. To add input element at L.ALS.Widgets.BaseWidget#toHtmlElement, use L.ALS.Widgets.BaseWidget#createInput

Inherited From:
Returns:

Input element

Type
HTMLElement

<protected> createLabel()

Creates label for this widget

Inherited From:
Returns:

Label

Type
HTMLLabelElement

getEnabled()

Inherited From:
Returns:

True, if this widget is enabled. False otherwise.

Type
boolean

getLabelText()

Inherited From:
Returns:

Text of the label of this widget or locale property (if set)

Type
string

getObjectToSerializeTo(newObject, seenObjects)

Registers this object for serialization and deserialization. Returns an object to serialize custom properties to.

Call it first, if you implement your own algrorithm, and serialize to the returned object!

Parameters:
Name Type Description
newObject Object

Object to where you'll serialize

seenObjects Object

Already seen objects

Inherited From:
Returns:

Object to serialize to.

Type
Object

getValue()

Inherited From:
Overrides:
Returns:

Value of this widget

Type
*

isChecked()

Returns:
Type
*

<protected> onChange(event)

Being called when user changes this widget. Override it to add your functionality like validation.

Default implementation just returns true.

Parameters:
Name Type Description
event Event

Event fired by input

Inherited From:
Returns:

If true, the attached callback will be called.

Type
boolean

serialize(seenObjects)

Serializes this object to JSON. If overridden, you MUST perform following operations before returning JSON:

let json = {} // Your JSON
... // Perform serialization
json.constructorArguments = this.serializeConstrutorArguments(); // Serialize constructor arguments
json.serializableClassName = this.serializableClassName; // Add class name to JSON
return json; // Finally return JSON
Parameters:
Name Type Description
seenObjects Object

Already seen objects

Inherited From:
Returns:

This serialized object

Type
Object

serializeConstructorArguments()

Serializes constructor arguments. If your constructor is not empty, result of this method MUST be added to json at L.ALS.Serializable#serialize as "_construtorArgs" property.

Deprecated in favor of L.ALS.Serializable#getObjectFromSerialized which uses this function under-the-hood.

Inherited From:
Deprecated:
  • Yes
Returns:

Serialized constructor arguments

Type
Array

setChecked(isChecked)

Parameters:
Name Type Description
isChecked boolean | "true" | "false"

Check (true) or uncheck (false) this checkbox

Returns:

This

Type
L.ALS.Widgets.Checkbox

setConstructorArguments(args)

Sets constructor arguments for serialization

Parameters:
Name Type Description
args

Arguments to set

Inherited From:

setEnabled(isEnabled)

Sets whether this widget should be enabled or not

Parameters:
Name Type Description
isEnabled boolean
Inherited From:
Returns:

This

Type
L.ALS.Widgets.BaseWidget

setLabelText(text)

Sets label text

Parameters:
Name Type Description
text string

Text to set. Pass locale property to localize the label.

Inherited From:
Returns:

This

Type
L.ALS.Widgets.BaseWidget

setValue(value)

Sets value of this checkbox

Parameters:
Name Type Description
value boolean | "true" | "false"

Value to set

Overrides:
Returns:

This

Type
L.ALS.Widgets.Checkbox

shouldIgnoreEvent(event)

Whether ALS should ignore given event. If returns true, both L.ALS.Widgets.BaseWidget#onChange and (L.ALS.Widgets.BaseWidget#callCallback) won't be called, and none of the input's attributes will change. event.preventDefault() won't be called though.

Useful for precise control over your widget's behavior. For example, if your widget doesn't behave correctly when working with keyboard, here you can detect which actions shouldn't affect your widget.

You can also use event.preventDefault() here.

Parameters:
Name Type Description
event Event

Event that should be passed or ignored.

Inherited From:
Returns:

True, if event should be skipped.

Type
boolean

<protected> toHtmlElement()

Builds this widget, i.e. creates container and puts label and input here.

Default implementation is:

let container = this.createContainer();
container.appendChild(this.createLabel());
container.appendChild(this.createInput());
return container;
Inherited From:
Overrides:
Returns:

HTML representation of this widget

Type
HTMLDivElement