Skip to content

Using the Toggle Component

Original guide · All levels

Intro The тoggle component is a simple, but quite handy component. It can be used to toggle visibility, styling, classes of the elements on your pages. In this tutorial we will show you a couple of ex

The тoggle component is a simple, but quite handy component. It can be used to toggle visibility, styling, classes of the elements on your pages.
In this tutorial we will show you a couple of examples - toggling visibility and toggling a class.

As all the App Connect components, the toggle component should be added in the App Structure, before you can use it. Right click App:

The toggle component has been added to your page:

Section titled “The toggle component has been added to your page:”

The way the toggle component works is quite simple. It has two states - checked and not checked`
Its state can be changed using the dynamic events.

The properties of the toggle component are also quite simple. Its default state is unchecked, but you can also change it to checked in the properties:

You can easily toggle the visibility of any element using the toggle component. We’d like to toggle the visibility of a div block on our page, when clicking the button:

So select the element and add new dynamic attribute:

Section titled “So select the element and add new dynamic attribute:”

Click the dynamic data picker to select when to show the element:

Section titled “Click the dynamic data picker to select when to show the element:”

Now, let’s setup the button. Select the button or the element you want to use to control the toggle with:

Section titled “Now, let’s setup the button. Select the button or the element you want to use to control the toggle with:”

Then click the dynamic event picker icon to select the action for this event:

Section titled “Then click the dynamic event picker icon to select the action for this event:”

Select the toggle action, under the Toggle Component:

Section titled “Select the toggle action, under the Toggle Component:”

This will toggle the component state from checked to not checked and vice versa. Click Select:

Section titled “This will toggle the component state from checked to not checked and vice versa. Click Select:”

This will toggle the component state from checked to not checked and vice versa.
Click Select:

Save your page and preview the results. You can see that clicking the button toggles the visibility of the div:

You can use the toggle component, to toggle CSS classes for the elements on the page. We want to change the class of a div block on our page, when the button is clicked:

Select the div and add new dynamic attribute:

Section titled “Select the div and add new dynamic attribute:”

And enter the name of the class you want to toggle. We enter one of the standard Bootstrap classes bg-warning, which will make the background color yellow:

Then click the dynamic data picker, to select when to apply this class:

Section titled “Then click the dynamic data picker, to select when to apply this class:”

And select Toggle > Checked. So the class will be applied when the toggle component state is checked:

Section titled “And select Toggle > Checked. So the class will be applied when the toggle component state is checked:”

Now, let’s setup the button. Select the button or the element you want to use to control the toggle with:

Section titled “Now, let’s setup the button. Select the button or the element you want to use to control the toggle with:”

Then click the dynamic event picker icon to select the action for this event:

Section titled “Then click the dynamic event picker icon to select the action for this event:”

Select the toggle action, under the Toggle Component:

Section titled “Select the toggle action, under the Toggle Component:”

This will toggle the component state from checked to not checked and vice versa. Click Select:

Section titled “This will toggle the component state from checked to not checked and vice versa. Click Select:”

This will toggle the component state from checked to not checked and vice versa.
Click Select:

Save your page and preview the results. You can see the bg-yellow class is being toggled on button click:

Section titled “Save your page and preview the results. You can see the bg-yellow class is being toggled on button click:”