> For the complete documentation index, see [llms.txt](https://docs.appfarm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.appfarm.io/library/ui-components/switch.md).

# Switch

The UI component **Switch** allows the user to easily input data of type `boolean`. You can bind this UI component to a property, which can allow you to persist this user input to the database. They serve a very similar function to the [**Checkbox**](https://docs.appfarm.io/library/ui-components/checkbox.md) component.

{% hint style="info" %}
Showroom: [Switch example](https://showroom.appfarm.app/ui-components/switch), with its setup in Appfarm Create ([register](https://showroom.appfarm.app/sign-up) for access).
{% endhint %}

## Settings

Here are some of the properties in Appfarm Create which are custom for the **Switch**:

### Read Only and Disabled

When **Read-only** is true, the switch shows its value but the user cannot change it. When **Disabled** is true, the switch is shown as disabled.

### Value

The data source property or variable that the user input is bound to. This must be of data type `boolean`. This can be an App Variable, a Runtime Only Object Class property, or a Database Connected Object Class property.

{% hint style="warning" %}
A property of data type `boolean` is not automatically true or false by default. **A boolean property is by default `undefined`**. Binding a switch to such a property will display similarly to `false`. Once checked, the property is set to `true`. Once unchecked, the property is set to `false`.

Unless you want a boolean property to have more than 2 states (true or false) it is recommended to **have a default value** (see [Value on Create](https://docs.appfarm.io/reference/data-model/object-class-properties.md#general-properties)) set to `false` or `true`.

To make sure that you handle a value that has never been set the same way as `false`, it is also recommended to **use the following pattern in conditions** or filters to represent "equals false": **Use `NOT EQUALS true`**.

<img src="https://29237295-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiLU-xcHu0eLZiTxcmZ%2Fuploads%2FImqWzHUPUwQHvCV5AY6C%2Fimage.png?alt=media&amp;token=7ef153ee-28ca-408c-820d-66cedf02eba0" alt="" data-size="line">
{% endhint %}

### Label

This text gives further information about what the **Switch** means when it is either ticked or left unticked. This can be static text or bound to a data source, while a JavaScript can also be used to display more helpful and intuitive output to the user.

### Tab index

Users can use the `Tab` key to navigate between inputs and components on a screen. This property tells Appfarm Create which index to bind to the current **Switch**. This value should only be given when you want to override the default tab index. Using a tab index of `-1` will remove the component from the tab index.

### Appearance

**Color**

The color of the component can be configured to Primary (default), Secondary, Error, Info, Success, Warning or Default. These refer to the colors of the chosen app theme, while Default does not change the color of the switch.

**Margin**

Three choices are available for this property. These define the margin style between this component and other UI components on the screen.

* Normal
* Dense
* None

**Size**

Switches can be of size `Small` or `Medium` (default). An example of the difference in small vs medium size is available in the [Showroom](https://showroom.appfarm.app/ui-components/switch).

**Label placement**

Shown when a **Label** is set. Labels can be configured to appear at the `Start`, `End` (default), `Top` or `Bottom` of the **Switch** component.

### Event handlers

Event Handlers can detect a specific event occurring in Appfarm Create and can link these events to actions. One Event Handler is available for the **Switch** component:

**On value changed**: This Event Handler will run an action when a change is detected in the data source bound to the component. For example, if the data input changes from false to true, or vice versa, a specific action can be performed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.appfarm.io/library/ui-components/switch.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
