how to make a check box in kobo that when selected will render an input field
- User
how to make a check box in kobo that when selected will render an input field
Assistant
To create a checkbox in KoboToolbox (or KoboCollect) that, when selected, renders an input field, you can use Relevant Logic in your form design. This feature allows you to show or hide questions based on the user's input. Here's how to do it:
Steps to Create a Checkbox-Triggered Input Field
-
Open KoboToolbox Form Builder:
- Log in to your KoboToolbox account and open the form builder for the form you want to edit.
-
Add a Checkbox Question:
- Add a Select One or Select Multiple question type for the checkbox.
- For simplicity, use Select One with options like
YesandNo.
Example:
<select1 name="trigger_checkbox" label="Do you want to provide additional details?"> <item name="yes" label="Yes"/> <item name="no" label="No"/> </select1> -
Add an Input Field:
- Add a text input field (or any other input type) that you want to show when the checkbox is selected.
Example:
<text name="additional_details" label="Additional Details"/> -
Apply Relevant Logic:
- Use the
relevantattribute to control when the input field should appear. - Set the input field to be relevant only when the checkbox is selected (
yes).
Example:
<text name="additional_details" label="Additional Details" relevant="${trigger_checkbox} = 'yes'"> - Use the
-
Complete XML Structure: Here’s the complete XML structure for the form:
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa"> <h:head> <h:title>Checkbox Triggered Input Field</h:title> <model> <instance> <data id="checkbox-triggered-input"> <trigger_checkbox/> <additional_details/> </data> </instance> </model> </h:head> <h:body> <select1 name="trigger_checkbox" label="Do you want to provide additional details?"> <item name="yes" label="Yes"/> <item name="no" label="No"/> </select1> <text name="additional_details" label="Additional Details" relevant="${trigger_checkbox} = 'yes'"/> </h:body> </h:html> -
Save and Deploy:
- Save the form and deploy it to test the functionality.
Explanation
- The
relevantattribute uses XPath logic to determine when the input field should be displayed. ${trigger_checkbox} = 'yes'checks if the checkbox is set to "Yes" and shows the input field only if true.
Alternative: Using KoboToolbox Form Builder UI
If you prefer using the Form Builder UI instead of XML:
- Add a Select One question (for the checkbox).
- Add a Text question (for the input field).
- Click on the Text question, go to the Relevant field, and enter the condition:
(Replace${trigger_checkbox} = 'yes'trigger_checkboxwith the actual name of your checkbox question.)
This setup ensures the input field only appears when the checkbox is selected, providing a dynamic and user-friendly form experience.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.