How to Create Computed Fields
Computed fields are custom javascript functions used for computing data from the user input fields.
They're pretty similar to a cell with a formula in an Excel spreadsheet!


๐Ÿ”จ How to: Add a Computed Field

  • Select the Computed Field Icon and press Create New button.
  • Enter a key
  • Select a formula type: for now, we always recommend choosing Custom.
  • Choose which data inputs you'll need for your formula: we will have the possibility to choose between all the user input fields in the flow, and other computed fields result too.
  • Click Generate sample code - this will generate a basic javascript function that takes in the input variables that you selected. Write the function needed to process the data - make sure it returns a value.
  • Results output will appear in the Current Value field.
  • Once the Computed Field is finished, it will be available for display as a variable in other components.

๐Ÿ”จ How to: Use a Computed Field in a condition

  • Select a component and click the "Add a Show/Hide Condition" button, in the Options panel.
  • Select the computed field you created.
  • Select the condition you want to use.
  • Type the required result for the condition to be executed. Feel free to type a custom text value - it just needs to be exactly equal to the output of the Computed Field for the condition to pass.

Computed Field Examples

  • In this example, based on the budget of the potential client, you can recommend different plans. We select the budget input key on the User Data Input Fields, generate the sample code, and then write our function.
We can use the return value and some "Show/Hide Conditions" for a results page with our best fitting plan.
  • Here's another case where we use two keys: 'landscape' and 'activity'. Depending on the landscape and activity the user selected, we can recommend different locations.
We create all the possible results on the results page, and then add "Show/Hide Conditions" like this one:
  • In this example we're taking the user's input, checking if it is a full URL, and in case it's not, concatenating the necessary text to make it a full URL.
We can then access that value in any part of the flow just by adding 2 sets of curly brackets. In this case, the custom field was called "full_url" so if we type "{{full_url}}" it will show the return value.
Checkboxes Explained

Some Other Features

  • Fields to trigger updates: Will replace the Input Fields as the triggers for the computed field (but the "User Data Input Fields" still determine what data is passed into the function).
  • Watch + Include Full User Data: This is equivalent to adding everything into "User Data Input Fields", so it means every User Data property is both passed into the function and used for triggering it.
  • Async: Use this if the computed field needs to load data (so it returns a Promise).
  • Include Loading State: For async fields, whenever the input values change, the result will be _loading until it fetches the new data and returns the promise.
  • Cache Data: Savvy remembers what the result is for each combination of inputs (across all users!), so it doesn't have to run the function every time.