Skip to content
  • There are no suggestions because the search field is empty.

How to Make a Field Required/Not Required Based on a "Yes" or "No" Selection.

In OFS-Flow, you can create validation to make a field mandatory only when a specific answer, like "Yes," is chosen in a previous field. If "No" is selected, the field will remain optional. This is useful for forms where a "Yes" answer requires a mandatory comment or corrective action, but a "No" answer does not.

Scenario

You have two fields:

  1. A "Selection Box" named "Did you run a job?" with "Yes" and "No" options.

  2. A "Text Area" field named "Field A"

Goal: "Field A" must be completed if the user selects "Yes" on "Did you run a job?". It can be left empty if the user selects "No".

Configuration Steps

The validation rules are set on "Field A" and are processed in order from top to bottom.

Step 1 - Navigate to your alert and open the Form tab.

Step 2 - Select "Field A" and go to the Field Validation Rules tab.

Step 3 - Add the following rules in this specific order:

Rule 1: Mark as VALID if "No" is selected.

data["Did you run a job?"]=="no"
  • This rule checks the "MainCheck" field first. If it's "No", it marks the "DependentField" as valid, even if it's empty, and stops processing any further rules for this field.
  • Click on 'Valid' to set the status, colour and a message.

Screenshot 2025-11-12 at 3.59.27 pmTest:


Rule 2:
Mark as VALID if "Yes" is selected AND field is filled.

(data["Did you run a job?"]=="yes")&&(data["Field A"]!="")
  • This rule is only checked if Rule 1 was false (meaning "Yes" was selected). It marks the field as valid only if the user has entered any text.
  • Click on 'Valid' to set the status, colour and a message.

Screenshot 2025-11-12 at 4.01.39 pm
Test:


Rule 3:
Mark as INVALID (Catch-all).

1==1
  • This is the final "catch-all" rule. It will only be reached if the first two rules fail, which in this case means the user selected "Yes" but left the "Fields" empty.
  • Mark form as: Invalid (or Error to prevent submission)

  • With message: "This field is required when 'Yes' is selected."

Screenshot 2025-11-12 at 4.04.01 pm

 

Screenshot 2025-11-12 at 4.04.38 pm

Test: