Skip to content
This repository has been archived by the owner. It is now read-only.

Latest commit

 

History

History
1068 lines (741 loc) · 21.3 KB

File metadata and controls

1068 lines (741 loc) · 21.3 KB
layout post
title Properties, Methods and Events of ejToggleButton Widget
description API reference for ToggleButton
documentation API
platform js-api
keywords ToggleButton, Essential Angular ToggleButton, ToggleButton api

ejToggleButton

The Toggle Button allows you to perform the toggle option by using checked and unchecked state. This Toggle Button can be helpful to user to check their states. The Toggle Button control displays both text and images.

Syntax

{% highlight html %}

{% endhighlight %}

Example

{% highlight html %}

{% endhighlight %}

Requires

  • module:jQuery

  • module:ej.core.js

  • module:ej.togglebutton.js

  • module:ej.checkbox.js

Members

activePrefixIcon string

{:#members:activeprefixicon}

Specify the icon in active state to the toggle button and it will be aligned from left margin of the button.

N> This is applicable for the content type’s imageonly, textandimage, imagetextimage and imageboth.

Default Value

  • ""

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="play" activeText="Pause" [contentType]="contentType" [activePrefixIcon]="activePrefixIcon" [defaultPrefixIcon]="defaultPrefixIcon">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; activePrefixIcon: string; defaultPrefixIcon: string; constructor() { this.contentType = "textandimage"; this.activePrefixIcon="e-mediapause e-uiLight"; this.defaultPrefixIcon="e-mediaplay e-uiLight"; }; }

{% endhighlight %}

activeSuffixIcon string

{:#members:activesuffixicon}

Specify the icon in active state to the toggle button and it will be aligned from right margin of the button.

N> This is applicable for the content type’s imageonly, textandimage, imagetextimage and imageboth.

Default Value

  • ""

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [contentType]="contentType" [activeSuffixIcon]="activeSuffixIcon" defaultSuffixIcon="defaultSuffixIcon">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; activeSuffixIcon: string; defaultSuffixIcon: string; constructor() { this.contentType = "imageboth"; this.activeSuffixIcon="e-mediapause e-uiLight"; this.defaultSuffixIcon="e-mediaplay e-uiLight"; }; }

{% endhighlight %}

activeText string

{:#members:activetext}

Sets the text when ToggleButton is in active state i.e.,checked state.

Default Value

  • null

Example

{% highlight html %}

{% endhighlight %}

contentType enum

{:#members:contenttype}

Specifies the contentType of the ToggleButton. See ContentType as below

Name Description
TextOnly To specify the text contentType
ImageOnly To specify the image contentType
ImageBoth To specify the two images of contentType
TextAndImage To specify the Text and Image contentType
ImageTextImage To specify the image text and image contentType

Default Value

  • ej.ContentType.TextOnly

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [contentType]="contentType">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; constructor() { this.contentType = ej.ContentType.TextOnly; }; }

{% endhighlight %}

cssClass string

{:#members:cssclass}

Specify the CSS class to the ToggleButton to achieve custom theme.

Default Value

  • ""

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [cssClass]="customCss">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { customCss: string; constructor() { this.customCss = "gradient-lime"; }; }

{% endhighlight %}

defaultPrefixIcon string

{:#members:defaultprefixicon}

Specify the icon in default state to the toggle button and it will be aligned from left margin of the button.

N> This is applicable for the content type’s imageonly, textandimage, imagetextimage and imageboth.

Default Value

  • ""

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [contentType]="contentType" [activePrefixIcon]="activePrefixIcon" [defaultPrefixIcon]="defaultPrefixIcon">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; activePrefixIcon: string; defaultPrefixIcon: string; constructor() { this.contentType = "textandimage"; this.activePrefixIcon="e-mediapause e-uiLight"; this.defaultPrefixIcon="e-mediaplay e-uiLight"; }; }

{% endhighlight %}

defaultSuffixIcon string

{:#members:defaultsuffixicon}

Specify the icon in default state to the toggle button and it will be aligned from right margin of the button.

N> This is applicable for the content type’s imageonly, textandimage, imagetextimage and imageboth.

Default Value

  • ""

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [contentType]="contentType" [activeSuffixIcon]="activeSuffixIcon" [defaultSuffixIcon]="defaultSuffixIcon">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; activeSuffixIcon: string; defaultSuffixIcon: string; constructor() { this.contentType = "textandimage"; this.activeSuffixIcon="e-mediapause e-uiLight"; this.defaultSuffixIcon="e-mediaplay e-uiLight"; }; }

{% endhighlight %}

defaultText string

{:#members:defaulttext}

Specifies the text of the ToggleButton, when the control is a default state. i.e., unChecked state.

Default Value

  • null

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; constructor() { this.defaultText="Play"; this.activeText="Pause"; }; }

{% endhighlight %}

enabled boolean

{:#members:enabled}

Specifies the state of the ToggleButton.

Default Value

  • true

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText" [enabled]="true">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; constructor() { this.defaultText="Play"; this.activeText="Pause"; }; }

{% endhighlight %}

enablePersistence boolean

{:#members:enablepersistence}

Save current model value to browser cookies for maintaining states. When refreshing the ToggleButton control page, the model value is applied from browser cookies or HTML 5 local storage.

Default Value

  • false

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText" [enablePersistence]="true">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; constructor() { this.defaultText="Play"; this.activeText="Pause"; }; }

{% endhighlight %}

enableRTL boolean

{:#members:enablertl}

Specify the Right to Left direction of the ToggleButton.

Default Value

  • false

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText" [enableRTL]="true">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; constructor() { this.defaultText="Play"; this.activeText="Pause"; }; }

{% endhighlight %}

height number|string

{:#members:height}

Specifies the height of the ToggleButton.

Default Value

  • 28pixel

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText" [height]="height">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; height: string; constructor() { this.defaultText="Play"; this.activeText="Pause"; this.height= "28px"; }; }

{% endhighlight %}

htmlAttributes object

{:#members:htmlattributes}

It allows to define the characteristics of the ToggleButton control. It will helps to extend the capability of an HTML element.

Default Value

  • {}

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" [defaultText]="defaultText" [activeText]="activeText" [htmlAttributes]="htmlAttributes">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { defaultText: string; activeText: string; htmlAttributes: Object; constructor() { this.defaultText="Play"; this.activeText="Pause"; this.htmlAttributes= {disabled:"disabled"}; }; }

{% endhighlight %}

imagePosition enum

{:#members:imageposition}

Specifies the image position of the ToggleButton.

N> This image position is applicable only with the contentType property value set as textandimage. The images can be positioned in both imageLeft and imageRight options.

Name Description
ImageRight To specify Left position of the toggle button
ImageLeft To specify Right position of the toggle button
ImageTop To specify Top position of the toggle button
ImageBottom To specify Bottom position of the toggle button

Default Value

  • ej.ImagePosition.ImageLeft

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [contentType]="contentType" [imagePosition]="imagePosition" [activePrefixIcon]="activePrefixIcon" [defaultPrefixIcon]="defaultPrefixIcon">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { contentType: any; activePrefixIcon: string; defaultPrefixIcon: string; imagePosition: any; constructor() { this.contentType = ej.ContentType.TextAndImage; this.activePrefixIcon="e-mediapause e-uiLight"; this.defaultPrefixIcon="e-mediaplay e-uiLight"; this.imagePosition=ej.ImagePosition.ImageRight; }; }

{% endhighlight %}

preventToggle boolean

{:#members:preventtoggle}

Allows to prevents the control switched to checked (active) state.

Default Value

  • false

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [preventToggle]="false">

{% endhighlight %}

showRoundedCorner boolean

{:#members:showroundedcorner}

Displays the ToggleButton with rounded corners.

Default Value

  • false

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [showRoundedCorner]="true">

{% endhighlight %}

size enum

{:#members:size}

Specifies the size of the ToggleButton. See ButtonSize as below

Name Description
Mini To specify the minimum size of the toggle button
Small To specify the small size of the toggle button
Medium To specify the medium size of the toggle button
Large To specify the large size of the toggle button
Normal To specify the normal size of the toggle button

Default Value

  • ej.ButtonSize.Normal

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [size]="size">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { size: any; constructor() { this.size = ej.ButtonSize.Mini; }; }

{% endhighlight %}

toggleState boolean

{:#members:togglestate}

It allows to define the ToggleButton state to checked(Active) or unchecked(Default) at initial time.

Default Value

  • false

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [toggleState]="false">

{% endhighlight %}

type enum

{:#members:type}

Specifies the type of the ToggleButton. See ButtonType as below

Name Description
Button To create button with button type as button
Reset To create button with button type as reset
Submit To create button with button type as submit

Default Value

  • ej.ButtonType.Button

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [type]="type">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { type: any; constructor() { this.type = ej.ButtonType.Submit; }; }

{% endhighlight %}

width number|string

{:#members:width}

Specifies the width of the ToggleButton.

Default Value

  • 100pixel

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" [width]="width">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { width: string; constructor() { this.width = "100px"; }; }

{% endhighlight %}

Methods

destroy()

{:#methods:destroy}

Allows you to destroy the ToggleButton widget.

Example

{% highlight html %}

{% endhighlight %}

{% highlight ts %}

// Create instance of ToggleButton var toggleObj = $("#toggleButton").data("ejToggleButton"); toggleObj.destroy(); // destroy the toggle button

{% endhighlight %}

disable()

{:#methods:disable}

To disable the ToggleButton to prevent all user interactions.

Example

{% highlight html %}

{% endhighlight %}

{% highlight ts %}

// Create instance of ToggleButton var toggleObj = $("#toggleButton").data("ejToggleButton"); toggleObj.disable(); // disable the toggle button

{% endhighlight %}

enable()

{:#methods:enable}

To enable the ToggleButton.

Example

{% highlight html %}

{% endhighlight %}

{% highlight ts %}

// Create instance of ToggleButton var toggleObj = $("#toggleButton").data("ejToggleButton"); toggleObj.enable(); // enable the toggle button

{% endhighlight %}

Events

ejchange

{:#events:ejchange}

Fires when ToggleButton control state is changed successfully.

Name Type Description
cancel boolean if the event should be canceled; otherwise, false.
isChecked boolean return the toggle button checked state
model object returns the toggle button model
type string returns the name of the event

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" (ejchange)="onChange($event)">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { constructor() { } onChange(e: any){ // Your code here } }

{% endhighlight %}

ejclick

{:#events:click}

Fires when ToggleButton control is clicked successfully.

Name Type Description
cancel boolean if the event should be canceled; otherwise, false.
isChecked boolean return the toggle button checked state
model object returns the toggle button model
status boolean return the toggle button state
type string returns the name of the event

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" (ejclick)="onClick($event)">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { constructor() { } onClick(e: any){ // Your code here } }

{% endhighlight %}

create

{:#events:create}

Fires when ToggleButton control is created successfully.

Name Type Description
cancel boolean if the event should be canceled; otherwise, false.
model object returns the toggle button model
type string returns the name of the event

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" (create)="onCreate($event)">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { constructor() { } onCreate(e: any){ // Your code here } }

{% endhighlight %}

destroy

{:#events:destroy}

Fires when ToggleButton control is destroyed successfully.

Name Type Description
cancel boolean if the event should be canceled; otherwise, false.
model object returns the toggle button model
type string returns the name of the event

Example

{% highlight html %}

<ej-togglebutton type="checkbox" id="toggleButton" defaultText="Play" activeText="Pause" (destroy)="onDestroy($event)">

{% endhighlight %}

{% highlight ts %}

export class AppComponent { constructor() { } onDestroy(e: any){ // Your code here } }

{% endhighlight %}