A single command that toggles the checked/unchecked state of a field
🙏 Credit goes to Ulises RJ and Navigator Theo for coming up with this elegant solution! Join our community to share and learn about all things Tana 🫶
Goal
You want to build one command that toggles the state of something, like a checkbox. The key that unlocks this is the obscure Run commands in parallel
command, and this is an excellent use for it. The uses for a toggle are endless; this example will demonstrate how to build a visibility switch for command buttons.
Let's call it the single-command toggle.
Note: This is more like a proto-command, something that isn't useful on its own, but unlocks many creative uses.
Instructions
In the schema
- Create a checkbox field called is visible.
- In the Hide field setting, choose
Always
- In the Hide field setting, choose
- Create a command node for checking the is visible field:
- Name: visibility ON
- Add node filter:
>NOT:: >is visible:: true (checked)
- Add command Set field values
- In parameter
Fields to set: >is visible:: true (checked)
- Make another command node that removes the field:
- Name: visibility OFF
- Add node filter:
>is visible:: true (checked)
- Add command Remove fields
- In parameter
Fields to remove: is visible (field definition)
- Create a third command node for toggling between the two commands:
- Name: Toggle visibility
- Add command Run commands in parallel
- In the parameter
Commands to run
, add references to the two commands you created earlier
- Test the command out:
- On any node, run the command Toggle visibility. It should add the is visible field to it, checked. Running it again should remove the field.
The commands are now ready to go.
Configure visibility of command buttons
To configure the commands you want to toggle the visibility on, each command will need a node filter where the checked state of the is visible field determines whether they show up or not:
- Create or find a node that has many command buttons you want to hide
- For every command, add the
>Node filter:: >is visible:: true (checked)
- As you do this, the buttons should, one by one, disappear from the node.
Testing
Test the command again by running the Toggle visibility command on the node. It should make the buttons appear/disappear.
🙌 That's it!
Further ideas
- Bind a custom keyboard shortcut to Toggle visibility so you can easily toggle the visibility of buttons with the same keystrokes. See video above.
- Add the toggle command as a button: then you can toggle things with a mouse-click instead
- Use the same thing to toggle the visibility of related content sections