Follow

Field Rules and Skip Logic

Form Rules and Skip Logic

FastField supports skip logic and embedded rules. Rules can be written to perform the following actions:

  1. Hide or Show Fields
  2. Hide or Show Form Sections
  3. Set Fields as Required or Not Required
  4. Enable or Disable Fields

FastField can perform conditional "if/then" logic through the power of a Javascript execution engine.

To write a rule script, Tap the Rule button on while editing a specific field you'd like to a apply logic to. This will open a script text box. Type your rule script in the Rule text box.

Alt text

Referencing Field Values in Rules

To access a field value in a rule condition, wrap the field's field key with the '$' character. For example, for a field with a field key of 'first_name' you would use the following syntax to check if the First Name is 'John'.

if ($first_name$ == 'John')

Built in Functions

FastField supports built in functions in addition to the standard functions that you will find in the Javascript library. The following functions can be used to interact with the form model:

  • hide(optional fieldKey) - hide a field. If the Field Key is not specified, the field that the script is written for will used.

  • show(optional fieldKey) - show a field. If the Field Key is not specified, the field that the script is written for will used.

  • hideSection(optional sectionKey) - hides an entire section. If the Section Key is not provided, the current section will be used.

  • showSection(optional sectionKey) - shows an entire section. If the Section Key is not provided, the current section will be used.

  • required(optional fieldKey) - sets a field as required. If the Field Key is not specified, the field that the script is written for will used.

  • notRequired(optional fieldKey) - sets a field as not required. If the Field Key is not specified, the field that the script is written for will used.

  • disable(optional fieldKey) - sets a field as disabled. If the Field Key is not specified, the field that the script is written for will used.

  • enable(optional fieldKey) - sets a field as enabled. If the Field Key is not specified, the field that the script is written for will used.

  • float(value, emptyVal) - safely converts a value to a float

  • integer(value, emptyVal) - safely converts a value to an integer

  • bool(value) - safely converts a value to a boolean (true/false)

  • listContainsValues($list_field_key$, values) - checks if List from a List Selector field contains a set of values

  • listContainsValue($list_field_key$, value) - checks if List from a List Selector field contains a single value

  • sumSubform($subform$, 'fieldKey') - sums all the values of a Field Key within all instances of a particular subform

Examples

Hiding/Showing Fields

To hide a field through script, the 'hide' built in function can be used.

The following example illustrates how to hide the field if the 'married' switch field is set to true (Yes):

if ($married$ == true)
    show();
else
    hide();

Specifying Field Keys to Hide and/or Show Fields

The following example illustrates how to hide two fields with the same rule.

if ($married$ == true)
{
        show('spouse_name');
        show('spouse_age');
}
    else
{
        hide('spouse_name');
        hide('spouse_age');
}

Hiding/Showing Form Sections

To hide a section within a form through script, the 'hideSection' built in function can be used.

The following example illustrates how to hide a the section if the field with the field key of 'first_name' is equal to Sam.

if ($first_name$ == 'Sam')
    hideSection();
else
    showSection();

In the example above, All fields in the active section will be hidden when first name is equal to Sam and conversely, all fields will be visible if the first name is not equal to Sam.

Specifying Field Keys to Hide and/or Show Fields

To hide a specific section you can pass the section key as a parameter to the hideSection function.

The following example illustrates how to show/hide two sections with the same rule.

if ($have_children$ == true)
{
        showSection('children_data');
        showSection('marriage_data');
}
    else
{
        hideSection('children_data');
        hideSection('marriage_data');
}

Checking for Values in List

To check if a List Selector contains values you can use the listContainsValues function. The following example illustrates how to write these rules:

if (listContainsValues($favorite_color$,['red'])) && $age$ > 25)
    show();
else
    hide();

In the example above, the field is shown if the favorite color selected is red and the age is greater than 25.

Performing Calculations in Rules

You may also perform calculations such as:

int total = 0;
if ($married$ == true)
{
    total = $required_deposit$ * 2.0;
}
else
{
    total = $required_deposit$;
}   

if (total > 50)
{
    required();
}
else
{
    notRequired();
}

In the example above, the total is increased by 2 times the required deposit if the individual is married.

Safe Number Conversions

To convert a string (text) value to a numeric value, you can use the following built in functions to avoid null conversion errors:

  1. float(value, emptyVal)
  2. integer(value, emptyVal)

    if (float($height$) > 2.5)
    

This method will return 0 if the height is not a number. To provide your own default you can supply the second optional parameter emptyVal. In the following example, -99 would be returned if the height is not a number:

if (float($height$, -99) == -99)

Summarizing List Picker Scores

List Picker fields allow for a score to be set with each list item. In order to use the score value in a rule or a Computed Label field calculation use the same syntax as when referencing a field's value (e.g. wrap field key in $) but add a pound (#) symbol in front of the reference string. For example:

(#$listpicker_3$ + #$listpicker_11$) * 12
Have more questions? Submit a request

Comments

Powered by Zendesk