Switch Configuration

An object defining configuration options for the dxSwitch widget.

activeStateEnabled

A Boolean value specifying whether or not the widget changes its state when interacting with a user.

Type: Boolean
Default Value: true

This option is used when the widget is displayed on a platform whose guidelines include the active state change for widgets.

Show Example:
jQuery
<div data-bind="dxSwitch: { activeStateEnabled: enableActiveState }"></div>
<div class="dx-fieldset">
  <div class="dx-field">
    <div class="dx-field-label">Active state</div>
    <div class="dx-field-value" data-bind="dxCheckBox: { checked: enableActiveState }"></div>
  </div>
</div>
enableActiveState = ko.observable(true);
body{
  text-align: center;
}

clickAction

An action performed when the widget is clicked.

Type: Action
Default Value: null

Show Example:
jQuery
<div data-bind="dxSwitch: { clickAction: processClick }"></div>
processClick = function () {
  DevExpress.ui.notify("The widget has been clicked", "info", 1000);
}
body{
  text-align: center;
}

disabled

A Boolean value specifying whether or not a component can respond to user interaction.

Type: Boolean
Default Value: false

Create an observable variable and assign it to this option to specify the availability of the component at runtime.

Show Example:
jQuery
<div class="switch" data-bind="dxSwitch: { value: true, disabled: switchDisabled }"></div><br/>
<div class="dx-fieldset">
  <div class="dx-field">
    <div class="dx-field-label">Disabled</div>
    <div class="dx-field-value" data-bind="dxCheckBox: { checked: switchDisabled }"></div>
  </div>
</div>
switchDisabled = ko.observable(false);
body{
  text-align: center;
}
.switch{
  margin: 10px;
}

height

Specifies the height of the widget.

Type: Number|String|function
Default Value: undefined

The option can hold a value of the following types:

  • numeric - the height of the widget in pixels;
  • string - a CSS measurement of the widget height (e.g., "55px", "80%", "auto" and "inherit");
  • function - a function returning the widget height (e.g., height:function(){ return baseHeight - 10 + "%"; }).

offText

Text displayed when the widget is in a disabled state.

Type: String
Default Value: "OFF"

Show Example:
jQuery
<div class="switch" data-bind="dxSwitch: { onText: onTextValue, offText: offTextValue }"></div><br/>
<div class="dx-fieldset">
  <div class="dx-field">
    <div class="dx-field-label">On text</div>
    <div class="dx-field-value" data-bind="dxTextBox: { value: onTextValue }"></div>
  </div>
  <div class="dx-field">
    <div class="dx-field-label">Off text</div>
    <div class="dx-field-value" data-bind="dxTextBox: { value: offTextValue }"></div>
  </div>
</div>
onTextValue = ko.observable("ON");
offTextValue = ko.observable("OFF");
body{
  text-align: center;
}
.switch{
  margin: 10px;
}

onText

Text displayed when the widget is in an enabled state.

Type: String
Default Value: "ON"

Show Example:
jQuery
<div class="switch" data-bind="dxSwitch: { onText: onTextValue, offText: offTextValue }"></div><br/>
<div class="dx-fieldset">
  <div class="dx-field">
    <div class="dx-field-label">On text</div>
    <div class="dx-field-value" data-bind="dxTextBox: { value: onTextValue }"></div>
  </div>
  <div class="dx-field">
    <div class="dx-field-label">Off text</div>
    <div class="dx-field-value" data-bind="dxTextBox: { value: offTextValue }"></div>
  </div>
</div>
onTextValue = ko.observable("ON");
offTextValue = ko.observable("OFF");
body{
  text-align: center;
}
.switch{
  margin: 10px;
}

value

A Boolean value specifying whether the current switch state is "On" or "Off".

Type: Boolean
Default Value: false

Show Example:
jQuery
<div class="switch" data-bind="dxSwitch: { value: switchValue }"></div><br/>
<div class="button" data-bind="dxButton: { text: 'Change switch value', clickAction: changeSwitchValue }"></div>
switchValue = ko.observable(false);
changeSwitchValue = function(){
  switchValue(!switchValue());
};
body{
  text-align: center;
}
.switch{
  margin: 10px;
}
.button{
  margin-top:25px;
}

visible

A Boolean value specifying whether or not the widget is visible.

Type: Boolean
Default Value: true

width

Specifies the width of the widget.

Type: Number|String|function
Default Value: undefined

The option can hold a value of the following types:

  • numeric - the widget width in pixels;
  • string - a CSS measurement of the widget width (e.g., "55px", "80%", "auto" and "inherit");
  • function - the function returning the widget width (e.g., width:function(){ return baseWidth - 10 + "%"; }).