Skip logic in OpenSpecimen allows fields in custom forms to be dynamically shown or hidden based on the value of another field. This functionality ensures that forms adapt to user input, improving usability and reducing the likelihood of errors. Skip logic is defined using XML and retains its configuration even when the form is edited and saved via the UI.
|
Fields can be shown or hidden based on the value of dropdowns or radio buttons.
Skip logic can be applied based on specific text or numerical values.
Conditions can include ranges for numbers, dates, or text values.
Show/Hide Using Logical and Relational Operators:
Logical operators: and
, or
Relational operators: <
, >
, =
, <=
, >=
, !=
Complex expressions involving these operators can control field visibility.
Conditions based on regex.
Enabling or disabling fields (only show/hide is supported).
Skip logic cannot be applied to fields within sub-forms.
Create the form with all required fields via the UI.
Export the XML of the form using the Export button.
Edit the XML to define skip logic using the showWhen
tag.
Re-import the edited XML. Ensure the form name in the XML is unchanged to avoid creating a duplicate form.
Once imported, the skip logic is saved and remains functional even after subsequent updates via the UI.
Check the syntax of the "showWhen" tag in the above XML.
Sample form:
Form field | Control | Values | Control logic |
---|---|---|---|
Proband | Radio Button | Yes, No | - |
Relation with Proband | Drop down | Father, Mother, Son, Daughter, Others | The field should appear if option ‘No’ is selected for ‘Proband’ field |
Other Relation | String Text Box | - | The field should appear if option ‘Others’ is selected for ‘Relation with Proband’ field |
Try out the above sample form on the demo site: 'Genetic History'
On selecting 'Yes', the form field 'Relation with Proband' will not appear
On selecting 'No' option, form field 'Relation with Proband' will appear
Example of skip logic with condition involving logical operator:
Condition: Display 'FOBT Results' field when the value for 'FOBT Results' is either one of 'Positive' or 'Negative'
Syntax:
<showWhen><![CDATA[fOBTResults = "Positive" or fOBTResults = "Negative"]]></showWhen>
Example of skip logic to hide/show a subform
Condition: Display the subform "Family History Details" when the value of the field "Family Cancer History" is "Yes"
Syntax (to be added just above the subform control name): <showWhen><![CDATA[familyCancerHistory = "Yes" ]]></showWhen>
When 'Family Cancer History' value is 'No', subform does not appear.
When 'Family Cancer History' value is 'Yes', a subform 'Family History Details' is visible.
Example 3: Use Single checkbox in </showWhen>, since its boolean value, you need to mentioned 0/1 in the condition as below