Savvy Docs
  • Welcome
  • Guides
    • Intro to the builder
    • Designer Card
    • Options Card
    • Working with Logic
  • How-To's
    • General How-To's
      • βœ”οΈHow to select a container when I can’t click over it on the screen
      • πŸ‘οΈHow to hide a global component on a specific page
      • πŸ“ŠHow to calculate statistical significance from split test
      • πŸ…°οΈHow to install a Google font.
      • πŸ—’οΈHow to use "Logs" for debugging
      • ↩️How to change pages order
      • πŸŒ’How to select components that are behind the Embeddables card
      • πŸ“„How to clone a page
      • βž•How to add new components to a page
      • πŸ“„How to select the whole page
      • πŸ’»How to view your flow on different screen sizes
      • β›΅How to move between pages while editing your flow
    • Design How-To's
      • πŸ–‹οΈHow to style a specific component element (E.g. buttons image)
      • β­•How to style individual buttons (by button key) in Options Selectors
      • 🧿How to style a rounded bullet-like checkbox for options buttons
      • πŸ”²How to get rid of the default input outline
      • πŸ–ΌοΈHow to style a background image
      • 🦚How to style components (basics)
      • β†ͺ️How to change a component's location
      • ⬆️How to upload and apply images to your design
      • πŸ”˜How to style hover, selected, disabled button states
      • πŸͺΆHow to style CSS properties that are not there in the designer card (custom properties)
      • πŸ“±How to make my flow responsive
    • Logic How-To's
      • πŸ‘οΈHow to set show/hide conditions
      • πŸ“ΊHow to display a value previously entered by the user
      • βœ–οΈHow to add a β€œDeselect All” button in a Multi-Select
      • πŸ”¨How to use a computed field in a condition
      • πŸ‘οΈHow to hide a global component on a specific page
  • Other useful docs
    • Useful Docs
      • 🚦Conditions
      • πŸ‘©β€πŸ’»Computed Fields
      • πŸ”–Tags
    • WORK IN PROGRESS
      • ◻️Pending
        • Work in Progress: How the New Rendering Engine Works
        • Work in Progress: How to create a new Split test
        • Work in Progress: Preloading images
        • Work in Progress: How to show β€œloading…” while fetching or processing data
        • Work in Progress: How to send data to Tiktok
        • Work in Progress: How to send data to Postcript
        • Work in Progress: How to send data to Klaviyo
        • Work in Progress: How to send data to Google Tag
        • Work in Progress: How to send data to Google Analytics
        • Work in Progress: How to Fetch User Location Data to use in your Flow
        • Work in Progress: How to fetch job offers from Lever’s API
        • Work in Progress: How to fetch data and display the results as options in a dropdown
        • Work in Progress: How to create a new split test with 3 variants
        • Work in Progress: How to Duplicate a Container with All its Content
        • Work in Progress: How to add Chart.js to your flow
        • Work in Progress: How to Create Repeatable Button Components, Fetching from a Database
        • Work in Progress: How to Create a Global Column
        • Work in Progress: How to Clone a Flow
        • Work in Progress: How to Create and Style a Carousel
        • Work in Progress: How to Add Default User Data
        • Work in Progress: How to Show Validation Messages on Required Fields
        • Work in Progress: How to create an Option Selector Results Page
        • Work in Progress: How to create a combined Option Selector + Input component
        • Work in Progress: How to Add an Info Box Popup
        • Work in Progress: How to set up a Micro-Product as a Popup on your Site
        • Work in Progress: How to make a Full-Page Flow
        • Work in Progress: How to Use Custom Selectors
        • Work in Progress: How to Add a Video/GIF Placeholder to a Video Component
        • Work in Progress: How to Style Buttons
        • Work in Progress: How to Center Components
        • Work in Progress: How to Bring Data from Airtable
        • Work in Progress: How to add a custom font from a website:
        • Work in Progress: How to Create Computed Fields
        • Work in Progress: How to Ping an API
        • Work in Progress: How to Store a Password
        • Work in Progress: How to Bring Data from Google Sheet
        • Work in Progress: How to Fetch Safely from Savvy
        • Work in Progress: How To Fetch Data from a specific row in Airtable in a Computed Field
Powered by GitBook
On this page
  • Add a Computed Field(CF):
  • Other CF Examples:
  • Some Other Features
  1. Other useful docs
  2. WORK IN PROGRESS
  3. Pending

Work in Progress: How to Create Computed Fields

PreviousWork in Progress: How to add a custom font from a website:NextWork in Progress: How to Ping an API

Last updated 1 year ago

Sometimes you need to use some custom Javascript code in your flow. Here you'll learn how to do it with our builder

Add a Computed Field(CF):

As an example, we are going to use the case of a user entering a first name and last name on separated inputs and joining them together with a CF that returns the full name

  1. In the "Logic" card, in the "Computed Fields" tab, click the "Add" button.

  2. Select from the preset CF types or choose "Custom" (for this example we choose "custom").

  3. Name your CF by giving it a Key and click "Edit" (for this example we'll call it full_name).

  4. If you need the result of the CF stored select "Store locally" or "Store locally + in cloud". In most cases this is not necessary.

  5. Select the inputs you are going to use in the CF code by clicking "+ Add input". (for this example we'll need "first_name" and "last_name").

  6. You can set one of the inputs as the trigger so the CF doesn't execute until that input is entered. To do this click on "+ Add trigger" and select the desired input (for this example we'll assume the first name was entered first and then the last name so, we'll trigger when the last name is entered by selecting "last_name").

  7. Write your code. In our example the code would look something like this

function result({ first_name, last_name }) {
    return `${first_name} ${last_name}`
}

Other CF 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.

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.

◻️