Javascript Rule Builder

Build complex, powerful custom rules with JavaScript

Getting Started

By default, every rule starts out on the visual rule builder which means you must opt into using JavaScript.

You can opt-in to using JavaScript by navigating to your rule, clicking the "Code Editor" tab and then clicking "Edit Code" which will prompt you about opting into using JavaScript.

Once you convert your rule to using JavaScript, you can go back to the visual rule builder at anytime by clicking the "Rule Builder" tab.

Note: Opting back into the visual rule builder will restore the last state of the rule builder meaning any changes to the JavaScript code will be lost.

Feathery Context

The feathery object exposes the Context API to your rule's logic. Using this object, you can perform actions such as setting a field value, navigating to a step, setting custom errors and more. Full reference.

Accessing Form Fields

If the field's ID is a valid JavaScript variable name, then you can access the field directly through a field global that is pre-defined for your convenience.

For example:

// Interacting with a field using it's ID
myTextField.value = "some interesting text";

// Another example
MySelect.options = ["First Choice", "Second Choice"];

Note: Field globals are only available in logic rules running inside Feathery, not in SDK call-backs running outside of Feathery.

If the field ID is not a valid JavaScript variable name, then you can access the field using feathery.fields which is an object containing all keys.

For example:

// Interacting with a field that have invalid JavaScript variable names
feathery.fields["1st_name"].value = "first name";

// Another example
feathery.fields["last name"].value = "last name";

Each method of accessing the field will result in a Field object being returned. You can read more about the available methods and properties on the Field object here.

Rule Runtime

Rule are run synchronously in that a rule must complete before feathery runs other rules or continues with form processing. However, network requests made by rules may be either done from within the browser or on the server. In either case, the network request is asynchronous. If you want that network request to complete before continuing, you must await the request call. See an example of awaiting a network request here.

Last updated