What is a Field Key?
A field key is a unique identifier that is assigned to each field within a form. Field keys are used to reference a field in submission data, as well as in field rules (e.g., skip logic) and calculations.
All fields have field keys by default, which you can rename and edit manually. They are limited to letters, numbers, and underscores -- making it easier to type and remember them.
You can find the field key for each field in the General Settings menu of the form builder. You can also select Show Field Keys (under the Preview button) to view each field key directly in the form.
What do Field Keys do?
Field keys are used in internal form logic, automated workflows, and advanced calculations. It is best practice to organize your form fields to accurately reflect your submission data across all similar forms within your account.
Using Field Keys With Skip Logic and Rules
FastField supports skip logic and embedded rules in forms. You can write rules to perform the following actions:
- Hide or show fields
- Hide or show form sections
- Set fields as required or not required
- Enable or disable fields
- Other custom calculations
FastField can perform conditional "if/then" logic through the power of a JavaScript execution engine while referencing field keys.
To set up a rule for a specific field, select the Rules button next to the field you'd like to apply logic to. To set up form-level rules that involve multiple fields, go to Advanced Options > Advanced Rules. Once you're in the Field Rules or Form Rules window, you'll be able to create your rules scripts.
When using field keys within a calculation field, make sure to surround the field keys with $ signs. For example: $Cost$ - $Quantity$
Referencing Field Values in Rules
To access a field value in a rule condition, wrap the 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 be used.
- show(optional fieldKey) - show a field. If the field key is not specified, the field that the script is written for will be 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 be 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 be 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 be 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 be used.
- float(value, emptyVal) - safely converts a value to a float
- string(value) - converts value to a string
- 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$, ['value 1', 'value 2']) - checks if the list from a List Selector field contains a set of values
- listContainsValue($list_field_key$, ['value']) - checks if the list from a List Selector field contains a single value
- sumSubform($subform$, 'field key') - sums all the values of a field key within all instances of a particular subform
- hideOnReport('fieldKey') - conditionally hide a field from the default reports. If the field key is not specified, the field that the script is written for will be used.
- showOnReport('fieldKey') - conditionally show a field on the default reports. If the field key is not specified, the field that the script is written for will be used.
Example Scripts
Hiding/Showing Fields
To hide a field through the 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 the script, the hideSection built-in function can be used.
The following example illustrates how to hide 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 the 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 list contains values 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 2X the required deposit if the individual is married.