1

I am using Slate, and running a Foundry Function on Object (FoO) based on input from users of the application. However, anytime a user changes one of the input, the function re-runs, which seems inefficient.

Is there a way to run the Function only when a user clicks a specific button? I have tried using the conditional triggers, but the function still runs anytime a text field changes.

  • Hi and welcome to stack overflow. Would it be possible for you to include in your question an example of the FoO code you are trying to run with the parameter being passed? – fmsf May 20 '22 at 10:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 21 '22 at 13:24

1 Answers1

1

Slate is pretty powerful, and we can leverage the event system to do this properly. As we noticed, the function runs any time a change happens to one of its input. So we have to control when those changes happen. The way to do is is to have the following logical sequence of events:

  • Create a new variable (defaults to undefined is fine)
  • An event, fired when we click the button, computes the expected input of our Foundry Function from the input fields, and sets the variable.
  • The function input is the content of this variable - the function will only run when the variable changes (so, when we click the button)

This creates a sort of "gap" between the input fields and the function itself - the function will only run when the button is clicked.

In practice, this looks like this -

General setup of the application https://i.stack.imgur.com/41dAL.png

Create an empty variable, and add an event computing the expected input of your function when clicking the button https://i.stack.imgur.com/41dAL.png

Make sure that your function is using the variable as an input https://i.stack.imgur.com/41dAL.png

fmsf
  • 36,317
  • 49
  • 147
  • 195