# Using toggle component to create and delete data in the DB

**URL:** <https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094>\
**Category:** External Collections, Custom Actions & Collections\
**Created:** [March 9, 2021, 2:22am UTC](https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094 "2021-03-09T02:22:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Modusgot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/modusgot/32/6002_2.png) [@Modusgot](https://forum.adalo.com/u/Modusgot)\
**Post date:** [March 9, 2021, 2:22am UTC](https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094/1 "2021-03-09T02:22:14Z")

</div>

What’s up,  
I would love to use the “Toggle” component in a list to add and remove items in the Database (DB).

 ![Captura de Pantalla 2021-03-08 a la(s) 19.24.20](https://us1.discourse-cdn.com/flex020/uploads/adalo/original/2X/1/1defe8a36cf48a48dcdd6b0dc079631bf098f1d6.png)

My problem is that I can add data (rows) in the DB but I cannot delete if the user turns off the “Toggle”.

I’d like that if a user turn off “toggle”, in DB delete automatically row (Ord Paises Usua, for example):

 ![Captura de Pantalla 2021-03-08 a la(s) 20.16.48](https://us1.discourse-cdn.com/flex020/uploads/adalo/original/2X/e/e5401a8feaca04c1b5ea70a1f5b0bec809db2fda.png)

---

<div class="post-metadata">

**Author:** ![EdU](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/edu/32/6474_2.png) [@EdU](https://forum.adalo.com/u/EdU)\
**Post date:** [March 9, 2021, 12:39pm UTC](https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094/2 "2021-03-09T12:39:02Z")

</div>

this might be what you are looking for  
[https://help.adalo.com/action-basics/creating-an-action-that-triggers-data-edit](https://help.adalo.com/action-basics/creating-an-action-that-triggers-data-edit)

---

<div class="post-metadata">

**Author:** ![zmack](https://avatars.discourse-cdn.com/v4/letter/z/df788c/32.png) [@zmack](https://forum.adalo.com/u/zmack)\
**Post date:** [July 25, 2024, 6:50am UTC](https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094/3 "2024-07-25T06:50:48Z")

</div>

I have the same issue. Can add a record but not delete the same record, because the Collection doesn’t show up in the UI. Is this a known bug?

---

<div class="post-metadata">

**Author:** ![Victor](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.adalo.com/victor/32/2054_2.png) [@Victor](https://forum.adalo.com/u/Victor)\
**Post date:** [July 25, 2024, 10:00am UTC](https://forum.adalo.com/t/using-toggle-component-to-create-and-delete-data-in-the-db/10094/4 "2024-07-25T10:00:49Z")

</div>

Hi @zmack,

In order to delete a record, the component needs to have an access to it, i.e. Current Record must be available (on the page or from the list).  
In your case, when you add a Toggle, of course you can create a new record. But how can Toggle know that there is a Current record which should be deleted (and also, from where it can take this record?). When a Toggle appeared on the page, there was no record in question.

In such cases a workaround could be using 2 icons instead of toggle, wrapping 2nd icon into the list and and having a conditional visibility on both.

- 1st icon will serve for the state when the record is not created. Visibility condition should be set properly (I can’t say in details as I don’t know the criteria in your case), e.g. Collection\_Records → Count, where [condition] is equal to 0.
- For example, if you have a collection of Events, and you are creating an Event with the name “ABC”, the condition is set to Events → Count where Event Name = ABC is equal to 0. This means that the icon will be visible when there is no event with the name ABC.
- Add an action to the icon to create new record (from the example: new Event with name ABC).
- Then you add a 2nd icon, and convert it to a List. In our example, it’ll be a list of Events, where Event Name = ABC. So this list (and the icon) will appear **only** if there is a record with this name.
- And finally, you add the action to the 2nd icon (inside the list), which is Delete Current Event (from our example).

The resulting logic is: 1st icon appears when there are no events with the name ABC. User clicks on the icon, new Event is created. 1st icon disappears and a list with 2nd icon appears. User clicks on the 2nd icon, the event is deleted, list disappears and 1st icon appears.

**Please keep in mind** that because of how Adalo works the speed of how it works can be not very fast (app sends a request to the backend and receives a reply, and only after that the visual elements change). So some UI workarounds might be needed to mitigate these delays.

Best,  
Victor.
