Class ToggleSwitch

A control that lets the user switch an option between two states: on (checked is set to true) and off (checked is set to false).

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(element?: HTMLElement, options?: any): ToggleSwitch

Creates a new ToggleSwitch.

constructor

Parameters

  • element?: HTMLElement optional

    The DOM that hosts the control.

  • options?: any optional

    An object that contains one or more property/value pairs to apply to the new control. Each property of the options object corresponds to one of the control's properties or events. Event names must begin with "on". For example, to provide a handler for the change event, add a property named "onchange" to the options object and set its value to the event handler.

Returns

ToggleSwitch

Properties

public checked: boolean

Gets or sets a value that specifies whether the control is on or off.

public disabled: boolean

Gets or sets a value that specifies whether the control is disabled.

public element: HTMLElement

Gets the DOM element that hosts the ToggleSwitch.

public labelOff: string

Gets or sets the text that displays when the ToggleSwitch is off (checked is set to false).

public labelOn: string

Gets or sets the text that displays when the ToggleSwitch is on (checked is set to true).

public title: string

Gets or sets the main text for the ToggleSwitch control. This text is always displayed, regardless of whether the control is switched on or off.

Methods

public addEventListener(eventName: string, eventHandler: Function, useCapture?: boolean)

Registers an event handler for the specified event.

Parameters

  • eventName: string

    The name of the event to handle.

  • eventHandler: Function

    The event handler function to associate with the event.

  • useCapture?: boolean optional

    Set to true to register the event handler for the capturing phase; otherwise, set to false to register the event handler for the bubbling phase.

public dispatchEvent(type: string, eventProperties: any): boolean

Raises an event of the specified type and with additional properties.

Parameters

  • type: string

    The type (name) of the event.

  • eventProperties: any

    The set of additional properties to be attached to the event object when the event is raised.

Returns

boolean

true if preventDefault was called on the event, otherwise false.

public dispose()

Releases resources held by this ToggleSwitch. Call this method when the ToggleSwitch is no longer needed. After calling this method, the ToggleSwitch becomes unusable.

public handleEvent(event: any)

Handles the specified event.

Parameters

  • event: any

    The event.

public onchange(eventInfo: Event)

Occurs when the ToggleSwitch control is flipped to on (checked == true) or off (checked == false).

Parameters

  • eventInfo: Event

    An object that contains information about the event.

public raiseEvent(type: string, eventProperties: any): boolean

Raises an event of the specified type and with additional properties.

Parameters

  • type: string

    The type (name) of the event.

  • eventProperties: any

    The set of additional properties to be attached to the event object when the event is raised.

Returns

boolean

true if preventDefault was called on the event, otherwise false.

public removeEventListener(eventName: string, eventCallback: Function, useCapture?: boolean)

Removes an event handler that the addEventListener method registered.

Parameters

  • eventName: string

    The name of the event that the event handler is registered for.

  • eventCallback: Function

    The event handler function to remove.

  • useCapture?: boolean optional

    Set to true to remove the capturing phase event handler; set to false to remove the bubbling phase event handler.