Skip to content

Formulas

A sheet full of Wized formulas to give you an overview about common use cases

Sort Array

Filter a list of data.

TIP: If you want to sort a loaded array, make sure to save it to a variable after sorting. This makes sure you can use the sorted version of the array everywhere without needing to include this sort function everywhere.

Example: Sorted by name

js
{{r.4.d.sort((b,a)=>a.name>b.name ? 1 : -1)}}

If condition: Example 1

Example: Is true when request is running or has executed successfully

js
{{r.7.$.isRequesting || r.7.$.hasRequested && r.7.$.statusCode == 2}}

If condition: Example 2

Example: Returns name if name is present, otherwise returns “No name defined”

js
{{r.7.d.name ? r.7.d.name : “No name defined”}}

Invert boolean

Often used inside of if conditions.

js
{{!r.3.hasRequested}}

Format timestamp by locale

Example: Returns the date & time

js
{{
    const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: "numeric" };
    new Date(r.7.d.created_at).toLocaleDateString('en-US', options) + " " + new Date(r.7.d.created_at).toLocaleTimeString('en-US')
}}

Get timestamp

Example: Get the current timestamps in seconds (UNIX)

js
{
  {
    Math.floor(Date.now() / 1000);
  }
}

Convert number to string

The value type string is used for text.

js
{
  {
    String(120);
  }
}

Convert any value to Boolean

The value type boolean means true or false.

Example: Will return "true", because the string is not empty.

js
{
  {
    Boolean('this is a test');
  }
}

Add value to array

Used for example to add an id to an array of other id's. (Add item to list of liked items)

Example: To get the new list, you need to return the list after adding the item. => "r.1.d;"

js
{{
    r.1.d.push("2187289703");
    r.1.d;
}}

Find item in array

Example: Find an item in an array and return it.

js
{{r.5.d.items.find( i => i.name === "Peter" )}}

Remove item from array

Used for example to remove an id from an array of other id's. (Remove item from liked items)

Example: Find index of item you want to remove, remove item from array, then return edited array;

js
{{
    const index = r.5.d.items.findIndex( i => i.name === "Peter" );
    r.5.d.splice(index, 1);
    r.5.d;
}}

Trigger events on elements

This can be useful in actions & after request actions if for example you want to trigger the execution of a Webflow interaction.

Example: Select element with id 'test' and trigger manual click event

js
{
  {
    document.querySelector('#test').click();
  }
}

Select and manipulate an element on your page

Example: Editing first found element with class ‘’white-text’’

js
{{document.querySelector('.white-text').innerHTML = "Hello!”}}