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

  1. Create a checkbox field called is visible.
    1. In the Hide field setting, choose Always
  2. Create a command node for checking the is visible field:
    1. Name: visibility ON
    2. Add node filter: >NOT:: >is visible:: true (checked)
    3. Add command Set field values
    4. In parameter Fields to set: >is visible:: true (checked)
  3. Make another command node that removes the field:
    1. Name: visibility OFF
    2. Add node filter: >is visible:: true (checked)
    3. Add command Remove fields
    4. In parameter Fields to remove: is visible (field definition)
  4. Create a third command node for toggling between the two commands:
    1. Name: Toggle visibility
    2. Add command Run commands in parallel
    3. In the parameter Commands to run, add references to the two commands you created earlier
  5. Test the command out:
    1. 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.
Setup for the commands

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.
A node filter applied to the command button

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