Overview
In Frevvo, you often need to show, hide, or require specific fields based on a user's selection within a checkbox group. This guide provides a standard script to handle these dependencies effectively while ensuring hidden fields are cleared to maintain data integrity.
Why This Is Useful:
This approach keeps forms cleaner by only showing relevant questions to the user. It also ensures that if a user unchecks an option, any data they typed into the "dependent" field is wiped so it doesn't submit accidentally.
Implementation Script
Use the following logic in your Frevvo Rule. Ensure your Control Names (e.g., MainTrigger, Checkbox_Name) match your form design exactly.
// 1. Check if the Main Trigger (e.g. "Is help needed?") is set to 'Yes'
if (MainTrigger.value === 'Yes') {
Checkbox_Name.enabled = true;
Checkbox_Name.required = true;
// 2. Declare variables to track checkbox options
var isOption1 = false;
var isOption2 = false;
// 3. Loop through the checkbox array to see what is selected
for (var i = 0; i < Checkbox_Name.value.length; i++) {
if (Checkbox_Name[i].value === 'Option_Value_1') {
isOption1 = true;
}
if (Checkbox_Name[i].value === 'Option_Value_2') {
isOption2 = true;
}
}
// 4. Handle Option 1 Dependency
if (isOption1) {
Describe_Box1.enabled = true;
Describe_Box1.required = true;
} else {
Describe_Box1.enabled = false;
Describe_Box1.value = null; // Clear field when hidden
Describe_Box1.required = false;
}
} else {
// 5. Reset everything if the Main Trigger is 'No' or Empty
Checkbox_Name.enabled = false;
Checkbox_Name.value = null;
Describe_Box1.value = null;
}
Troubleshooting & Best Practices
| Problem |
Solution |
| Field never appears |
Verify the "Option_Value" matches the Value property in Frevvo (not the Label). |
| Field stays required when hidden |
Ensure you set .required = false inside the else block. |
| Old text remains in the hidden field |
You must set field.value = null; in the else block to clear background data when a field is hidden. |
Best Practice: Data Integrity
Always clear the value of a dependent field when it is hidden. This prevents "ghost data" from being processed in your workflow if a user changes their mind and unchecks an option.