Leave a comment at the end of this page or email contact@krishagni.com
How to set control (skip) logic in custom forms?
Introduction
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.
You need to know how to edit XMLs to define skip logic.
Skip logic can be configured only via XML import. We will enhance the UI to support this in future.
Skip logic is retained even if the form is edited and saved via UI (enhanced in v6.2).
What are the different types of skip logic supported?
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.
What is not supported currently?
Conditions based on regex.
Enabling or disabling fields (only show/hide is supported).
Skip logic cannot be applied to fields within sub-forms.
Best practices to create skip logic in a form
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.
Example form definition XML with skip logic: GeneticHistory.xml, Smoking History
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
Leave a comment at the end of this page or email contact@krishagni.com