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

Create an empty variable, and add an event computing the expected input of your function when clicking the button

Make sure that your function is using the variable as an input
