Queries based on toggle component

I have a toggle component, based on which I want to run different queries.

Toggle is on > query A

Toggle is off > query B

What’s the best way to do it?

1 Like

Hi @Sara, Welcome to Retool Community.

I understand the issue you're facing. If your goal is to trigger different queries when a toggle is switched on or off, you can achieve this using On Change event handlers.

Steps

  1. Select your Toggle/Switch component.
  2. Add two On Change event handlers.
  3. Configure each event to trigger the appropriate query.
  4. For each event, use the Only run when condition to control when it executes.

For example:

  • Query 1:
switch1.value === true
  • Query 2:
switch1.value === false

This way, when the toggle is turned on, the first query will run, and when it is turned off, the second query will run.

I've attached screenshots below showing the configuration:

I hope this helps! Let me know if you need any additional assistance.

1 Like