diff --git a/source/_static/files/getting_started_xlsform/sample_xlsform.xlsx b/source/_static/files/getting_started_xlsform/sample_xlsform.xlsx new file mode 100644 index 000000000..4f1e14100 Binary files /dev/null and b/source/_static/files/getting_started_xlsform/sample_xlsform.xlsx differ diff --git a/source/_static/files/select_from_map_xls/Placeholder.md b/source/_static/files/select_from_map_xls/Placeholder.md new file mode 100644 index 000000000..3b94f9157 --- /dev/null +++ b/source/_static/files/select_from_map_xls/Placeholder.md @@ -0,0 +1 @@ +Placeholder diff --git a/source/_static/files/select_from_map_xls/SelectFromMap.xlsx b/source/_static/files/select_from_map_xls/SelectFromMap.xlsx new file mode 100644 index 000000000..6429c6472 Binary files /dev/null and b/source/_static/files/select_from_map_xls/SelectFromMap.xlsx differ diff --git a/source/_static/files/select_from_map_xls/cities1.csv b/source/_static/files/select_from_map_xls/cities1.csv new file mode 100644 index 000000000..ece4fea52 --- /dev/null +++ b/source/_static/files/select_from_map_xls/cities1.csv @@ -0,0 +1,6 @@ +name,label,geometry,info,marker-color,marker-symbol +1,Warsaw,52.2297 21.0122 0 0,Capital city of Poland,#FF0000,W +2,Berlin,52.5200 13.4050 0 0,Capital city of Germany,, +3,Paris,48.8566 2.3522 0 0,Capital city of France,#FFFFFF,P +4,Kyiv,50.4501 30.5234 0 0,Capital city of Ukraine,#7d3f00,🙂 +5,Prague,50.0755 14.4378 0 0,Capital city of the Czech Republic,#00ff00, \ No newline at end of file diff --git a/source/_static/files/select_from_map_xls/cities2.geojson b/source/_static/files/select_from_map_xls/cities2.geojson new file mode 100644 index 000000000..23d1267f0 --- /dev/null +++ b/source/_static/files/select_from_map_xls/cities2.geojson @@ -0,0 +1,87 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "title": "Warsaw", + "info": "Capital city of Poland", + "id": "1", + "marker-color": "#FF0000", + "marker-symbol": "W" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 21.0122, + 52.2297 + ] + } + }, + { + "type": "Feature", + "properties": { + "title": "Berlin", + "info": "Capital city of Germany", + "id": "2" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 13.4050, + 52.5200 + ] + } + }, + { + "type": "Feature", + "properties": { + "title": "Paris", + "info": "Capital city of France", + "id": "3", + "marker-color": "#FFFFFF", + "marker-symbol": "P" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 2.3522, + 48.8566 + ] + } + }, + { + "type": "Feature", + "properties": { + "title": "Kyiv", + "info": "Capital city of Ukraine", + "id": "4", + "marker-color": "#7d3f00", + "marker-symbol": "🙂" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 30.5234, + 50.4501 + ] + } + }, + { + "type": "Feature", + "properties": { + "title": "Prague", + "info": "Capital city of the Czech Republic", + "id": "5", + "marker-color": "#00ff00" + }, + "geometry": { + "type": "Point", + "coordinates": [ + 14.4378, + 50.0755 + ] + } + } + ] +} \ No newline at end of file diff --git a/source/_static/files/select_from_map_xls/cities3.xml b/source/_static/files/select_from_map_xls/cities3.xml new file mode 100644 index 000000000..54910177c --- /dev/null +++ b/source/_static/files/select_from_map_xls/cities3.xml @@ -0,0 +1,39 @@ + + + 1 + + 52.2297 21.0122 0 0 + Capital city of Poland + #FF0000 + W + + + 2 + + 52.5200 13.4050 0 0 + Capital city of Germany + + + 3 + + 48.8566 2.3522 0 0 + Capital city of France + #FFFFFF + P + + + 4 + + 50.4501 30.5234 0 0 + Capital city of Ukraine + #7d3f00 + 🙂 + + + 5 + + 50.0755 14.4378 0 0 + Capital city of the Czech Republic + #00ff00 + + diff --git a/source/appearances_xls.md b/source/appearances_xls.md new file mode 100644 index 000000000..000d1d2e5 --- /dev/null +++ b/source/appearances_xls.md @@ -0,0 +1,134 @@ +# Question appearances in XLSForm +**Last updated:** Oct 31, 2025 + +Question appearances allow you to customize how questions are displayed in the form and the type of responses they collect. This article explains how to add question appearances in XLSForm and lists common appearances by question type. + +It is important to note that some appearances only work in [Enketo web forms](https://support.kobotoolbox.org/enketo.html), while others are supported only in [KoboCollect](https://support.kobotoolbox.org/kobocollect_on_android_latest.html). Consider your data collection method when selecting appearances. + +

+ Note: This article focuses on setting question appearances in XLSForm. To learn about setting appearances in the KoboToolbox Formbuilder, see Using the Formbuilder documentation. +

+For hands-on practice with question appearances in XLSForm, see KoboToolbox Academy's XLSForm Fundamentals Course. +

+ +## Adding question appearances + +To add question appearances in XLSForm: +1. In the `survey` worksheet, add an **appearance** column. +2. Enter the name of the appearance in the `appearance` column. Ensure you use the exact spelling and punctuation of the appearance name. +3. Some appearances can be combined and applied to the same question. Combine appearances by entering them in the same cell and separating them with a space. + +**survey worksheet** + +| type | name | label | appearance | +| :--- | :--- | :--- | :--- | +| text | description | Describe the project. | multiline | +| select_one country_list | country | Which country is this project taking place in? | autocomplete minimal | +| survey | + + +## Available question appearances in XLSForm +The tables below list common question appearances by question type and shows which are supported in Enketo web forms and KoboCollect. + +### Select question types +Select questions allow respondents to [choose from predefined options](https://support.kobotoolbox.org/question_types_xls.html#select-question-types). + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `minimal` | Displays choices in a drop-down menu. | Enketo and KoboCollect | +| `compact` | Displays choices side-by-side with minimal padding and without choice boxes. | Enketo and KoboCollect | +| `label` | Displays choice labels without the choice boxes. | Enketo and KoboCollect | +| `list-nolabel` | Displays the answer choice boxes without the labels. | Enketo and KoboCollect | +| `autocomplete` | Adds a search bar at the top of the option list. | Enketo and KoboCollect (combine with minimal appearance) | +| `horizontal` | Displays the answer choices horizontally in columns. | Enketo only | +| `horizontal-compact` | Displays the answer choices horizontally, with minimal padding and without choice boxes. | Enketo only | +| `likert` | Displays answer choices as a Likert scale (`select_one` only). | Enketo and KoboCollect | +| `quick` | Auto-advances the form to the next question after an answer is selected (`select_one` only). | KoboCollect only | +| `quickcompact` | Displays choices side-by-side with minimal padding and without choice boxes, and auto-advances to the next question after an answer is selected (`select_one` only). | KoboCollect only | +| `columns` | Displays available choices in 2, 3, 4 or 5 columns depending on screen size. | Enketo and KoboCollect | +| `columns-pack` | Displays available choices with as many as possible on one line. | Enketo and KoboCollect | +| `columns-n` | Displays available choices in the specified number (n) of columns. | Enketo and KoboCollect | +| `map` | Displays a map to select options from. Requires defining GPS coordinates in the `choices` sheet (`select_one` only). | KoboCollect only | +| `quick map` | Displays a map to select options from, automatically recording the first selected location without displaying additional information. Requires defining GPS coordinates in the `choices` sheet (`select_one` only). | KoboCollect only | + +

+ Note: Appearances for select_one and select_multiple questions can also be used for select from file questions. +

+ +### Integer and decimal question types +Numeric questions are used to [collect whole numbers or decimal numbers](https://support.kobotoolbox.org/question_types_xls.html#numeric-question-types). + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `thousands-sep` | Formats large numbers using a comma separator for thousands. | Enketo and KoboCollect | +| `bearing` | Records a compass reading in degrees (`decimal` only). | KoboCollect only | +| `counter` | Displays buttons for increasing and decreasing digits (`integer` only). | KoboCollect only | + + +### Range question type +Range questions are used to [select values within a specified range](https://support.kobotoolbox.org/question_types_xls.html#numeric-question-types). + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `vertical` | Changes the orientation of the number line to a vertical line. | Enketo and KoboCollect | +| `picker` | In KoboCollect, displays a pop-up spinner for selecting values. In Enketo, displays a drop-down menu. | Enketo and KoboCollect | +| `rating` | Displays stars instead of a number line. | Enketo and KoboCollect | +| `distress` | Displays a thermometer instead of a number line. | Enketo and KoboCollect | + + +### Text question type +Text questions allow users to [collect open-ended responses](https://support.kobotoolbox.org/question_types_xls.html#text-and-note-question-types). + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `numbers` | Displays a numeric keyboard instead of a text keyboard (e.g., to collect phone numbers). | KoboCollect only | +| `multiline` | Displays a multiline text box for longer text responses. | Enketo and KoboCollect | +| `url` | Displays a clickable URL under the question text and makes the question read-only. Requires entering a URL in the question's `default` column. Also works with `note` questions. | Enketo and KoboCollect | +| `masked` | Masks text entered by the respondent (e.g., a password or confidential information). | KoboCollect only | + + +### Date question type +Date questions are used to [capture specific calendar dates](https://support.kobotoolbox.org/question_types_xls.html#date-and-time-question-types). + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `month-year` | Captures a month and a year. | Enketo and KoboCollect | +| `year` | Captures only a year. | Enketo and KoboCollect | +| `no-calendar` | Displays a spinner to select the day, month, and year, instead of the default calendar-style picker. | KoboCollect only | +| `coptic` | Displays the Coptic calendar. | KoboCollect only | +| `ethiopian` | Displays the Ethiopian calendar. | KoboCollect only | +| `islamic` | Displays the Islamic calendar. | KoboCollect only | +| `bikram-sambat` | Displays the Bikram Sambat calendar. | KoboCollect only | +| `myanmar` | Displays the Myanmar calendar. | KoboCollect only | +| `persian` | Displays the Persian calendar. | KoboCollect only | +| `buddhist` | Displays the Buddhist calendar. | KoboCollect only | + + +### GPS question types +GPS questions are used to [capture the geographic coordinates](https://support.kobotoolbox.org/question_types_xls.html#gps-question-types) of a location, path, or area directly within your forms. + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `maps` | Displays a map for users to visualize the location that is being automatically recorded (`geopoint` only). | KoboCollect only (included in default Enketo appearance) | +| `placement-map` | Allows for manual selection of a location on a map (`geopoint` only). | KoboCollect only (included in default Enketo appearance) | +| `hide-input` | Shows a larger map and hides other input fields (latitude, longitude, altitude, accuracy). | Enketo only | + + +### Image questions +Image questions allow users to [upload or record images](https://support.kobotoolbox.org/question_types_xls.html#media-question-types) directly into their forms. + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `signature` | Allows users to draw their signature. | Enketo and KoboCollect | +| `draw` | Allows users to sketch or create drawings. | Enketo and KoboCollect | +| `annotate` | Allows users to annotate an image by drawing or writing on it. | Enketo and KoboCollect | +| `new` | Prompts users to take a new picture using the device camera (no file upload). | KoboCollect only | +| `new-front` | Prompts users to take a new picture using the device's front-facing camera. | KoboCollect only | + + +### Barcode questions +Barcode questions allow users to [scan a QR code](https://support.kobotoolbox.org/question_types_xls.html#media-question-types) using the device's camera in KoboCollect. + +| Appearance | Description | Compatibility | +| :--- | :--- | :--- | +| `hidden-answer` | Hides the scanned barcode value. | KoboCollect only | diff --git a/source/calculations_xls.md b/source/calculations_xls.md new file mode 100644 index 000000000..781b24c84 --- /dev/null +++ b/source/calculations_xls.md @@ -0,0 +1,148 @@ +# Adding calculations in XLSForm + +Calculations can be used inside your form to derive new variables, build advanced form logic, and display results to respondents during data collection. + +Calculations are processed within the form, helping save time during data analysis. The results are stored as new columns in the final dataset and can be used throughout the form to apply [skip logic](https://support.kobotoolbox.org/skip_logic_xls.html), set [constraints](https://support.kobotoolbox.org/constraints_xls.html), or display [dynamic content](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing) in question labels and notes. + +This article explains how to add calculations in XLSForm, covering both basic arithmetic and more advanced expressions. + +

+Note: This article focuses on adding calculations in XLSForm. To learn about adding calculations in the KoboToolbox Formbuilder, see Calculate question type. +

+For hands-on practice with calculations in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Adding calculations in XLSForm + +Calculation expressions are constructed using a combination of [question references](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing), [mathematical operators](https://support.kobotoolbox.org/form_logic_xls.html#mathematical-and-comparison-operators), [functions](https://support.kobotoolbox.org/functions_xls.html), and constants. + +To add a calculation in your XLSForm: +1. In the `type` column of the `survey` worksheet, enter **calculate** to add a `calculate` question type. +2. Enter a `name` for the `calculate` question. + - Because the calculation is not displayed in the form, the `calculate` question does not require a **label**. +3. Add a **calculation** column in the `survey` worksheet. +4. In the `calculation` column, enter the **calculation expression.** + - Calculations can range from [basic arithmetic calculations](https://support.kobotoolbox.org/calculations_xls.html#arithmetic-calculations) to [advanced calculations](https://support.kobotoolbox.org/calculations_xls.html#advanced-calculations) using functions and regular expressions. + +To refer to the calculation output in the rest of your form (e.g., inside a note question, question label, or form logic), use the [question referencing](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing) format **${question_name}**, where `question_name` is the **name** of the `calculate` question. + +**survey worksheet** + +| type | name | label | calculation | +|:----------|:--------------|:-------------------------------|:----------------------| +| integer | bags | Total number of bags sold | | +| decimal | price | Price per bag | | +| calculate | total_amount | | ${bags} * ${price} | +| note | display_total | The total is ${total_amount} | | +| survey | + +## Arithmetic calculations + +Calculations in XLSForm can range from simple arithmetic calculations to advanced derivation of variables. + +Arithmetic calculations allow you to perform basic calculations using the following **operators**: + +| Operator | Description | +|:----------|:-------------| +| + | Addition | +| - | Subtraction | +| * | Multiplication | +| div | Division | +| mod | Modulo (calculates the remainder of a division) | + +Calculations in XLSForm follow the **BODMAS** rule for the order of mathematical operations: **B**rackets, **O**rder of powers, **D**ivision, **M**ultiplication, **A**ddition, and **S**ubtraction. This means that calculations within brackets (or parentheses) are performed first, followed by powers, then divisions, multiplications, and so on. Using brackets correctly ensures that your calculations function as expected. + +## Advanced calculations + +Advanced calculations in XLSForm often rely on **functions** and **regular expressions** to make calculations more efficient. +* **Functions** are predefined operations used to automatically perform complex tasks like rounding values, calculating powers, or extracting the current date. +* **Regular expressions (regex)** are search patterns used to match specific characters within a string of text. + +

+ For a comprehensive list of functions available in XLSForm, see Using functions in XLSForm. To learn more about regular expressions, see Restricting text responses with regular expressions. +

+ +Examples of more advanced calculations include: + +| Calculation | Description | +|:-------------|:-------------| +| `int((today()-${DOB}) div 365.25)` | Calculate age from date of birth. | +| `int(today()-${date})` | Calculate days since a date. | +| `format-date(${date}, '%b')` | Return just the month from a date. | +| `concat(${first}, " ", ${middle}, " ", ${last})` | Create a single string with a respondent’s full name. | +| `jr:choice-name(${question1}, '${question1}')` | Return a choice’s label, in the current language, from the choice list. | +| `translate(${full_name}, "ABCDEFGHIJKLMNOPQRSTUVWXYZ ", "abcdefghijklmnopqrstuvwxyz_")` | Convert uppercase letters to lowercase and spaces to underscores. | +| `substr(${question}, 1, 2)` | Keep only the 1st letter or number in a string. | +| `int(random()*10)` | Generate a random number between 0 and 10. | +| `selected-at(${gps}, 0)` | Isolate latitude from GPS coordinates. | +| `selected-at(${gps}, 1)` | Isolate longitude from GPS coordinates. | +| `if(regex(${id}, '^ML-'), 'yes', 'no')` | Create a binary variable that takes `yes` if the respondent ID starts with “ML-”. | + +### Setting dynamic default responses + +The `calculation` field can also be used to set **dynamic default responses.** Dynamic default responses allow you to display a default response inside a question based on a previous response. + +To set a dynamic default response: +1. In the `calculation` column, enter the **reference to the question** that will dynamically populate the default response. +2. In the `trigger` column, enter the question that will activate the calculation. + - Typically, this would be the same question referenced in the `calculation` column, so that any change to the trigger question will also update the default response. + +**survey worksheet** + +| type | name | label | calculation | trigger | +|:------|:-----------|:--------------------------|:-------------|:-------------| +| text | hh_name | Name of the head of household | | | +| text | phone | Household phone number | | | +| text | phone_name | Name of the phone owner | ${hh_name} | ${hh_name} | +| survey | + +

+Note: If you want to prevent users from editing the field, set the read_only column to TRUE. +

+ +## Troubleshooting + +
+ Troubleshooting recommendations + To facilitate troubleshooting, display calculation outputs in a note while developing your form. This helps determine if the calculation is evaluating correctly and makes identifying issues easier. You can also break down long expressions into smaller ones and display the output of each to pinpoint problems. +
+ +
+ +
+ Calculations not working properly + If your calculations are not working, check the following: + +
+ +
+ +
+ Dealing with empty fields + Unanswered questions are treated as empty strings and will not automatically convert to zero. When an empty value is used in a calculation, it results in "Not a Number" (NaN). To convert empty values to zero for calculations, use the coalesce() or if() functions. For example: + + Another option is to set default values for each of the numeric variables to 0 in the default column. +
+ +
+ +
+ Calculations keep changing in the form + Expressions are re-evaluated as an enumerator progresses through a form. This is especially important for functions not connected to fields in the form, such as random() or now(), as their values may change under these conditions. +

+Expressions are re-evaluated when: + + To control when an expression is evaluated, set a trigger to evaluate it only when a given question is answered, or the function once() to ensure the expression is only evaluated once (e.g., once(random()) or once(today())). +
diff --git a/source/choice_filters_xls.md b/source/choice_filters_xls.md new file mode 100644 index 000000000..b5818f20f --- /dev/null +++ b/source/choice_filters_xls.md @@ -0,0 +1,168 @@ +# Adding choice filters in XLSForm + +Choice filters create dynamic forms where options in one question depend on the answer to a previous question. This streamlines data collection by presenting only relevant choices, improving survey efficiency and accuracy. + +Choice filters can be used for various applications, including: +- **Hierarchical lists**, such as continents and countries, where the list of countries depends on the selected continent (also known as **cascading selects**). +- **Removing one or multiple options from a list** if they are irrelevant for a respondent based on their previous answers. +- **Reusing a list of options** in XLSForm for multiple questions, where the list varies slightly from one question to the next. +- Reusing a list of options from a previous question, including **only options that were selected by the respondent.** + +This article explains how to add choice filters in XLSForm and includes examples for different use cases. Choice filters are defined in the `choice_filter` column of the `survey` worksheet, and operationalized in the `choices` worksheet. + +

+Note: This article focuses on adding choice filters in XLSForm. To learn about adding cascading select questions in the KoboToolbox Formbuilder, see Adding cascading select questions in the Formbuilder. +

+For hands-on practice with choice filters in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Adding static choice filters + +**Static choice filters** apply the same filtering conditions for all respondents. When using static choice filters, a list of options is filtered, but it does not vary based on previous responses. This can be useful when you want to reuse a list of options across multiple questions in your form with minor variations, without duplicating the choice list multiple times in your `choices` worksheet. + +To add static choice filters in XLSForm: +1. Add a `select_one` or `select_multiple` question to your XLSForm and [define your option choices](https://support.kobotoolbox.org/option_choices_xls.html) in the `choices` worksheet. +2. In the `choices` worksheet, add a filter column. + - You can name this column anything you choose (e.g., `q2`). +3. In the filter column, write any value (e.g., `yes`) next to the choice(s) you want to include in the choice list for your question. + - This value will act as the filter. It can be any word or number. +4. In the `survey` worksheet, add a **choice_filter** column. This column will contain the **choice filter expression** used to filter the option choices. + - The choice filter expression in its most basic form will take the format: **filter = ‘value’.** + - For example, `q2 = ‘yes’` will retain all choices with **yes** in the `q2` column. + +### Example + +In the example below, the same list of choices (`activities`) is used for two different questions. For the second question, the list is filtered to show only outdoor activities. + +**survey worksheet** + +| type | name | label | choice_filter | +|:-----------------|:------------------|:--------------------------------------------------------|:----------------| +| select_one activities | activities | What activities do you enjoy doing in your free time? | | +| select_one activities | outdoors_activities | Which of these outdoor activities are available in your city? | filter = 'outdoors' | +| survey | + +**choices worksheet** + +| list_name | name | label | filter | +|:-----------|:-----------|:--------------------|:---------| +| activities | reading | Reading | | +| activities | swimming | Swimming | outdoors | +| activities | running | Running | outdoors | +| activities | television | Watching television | | +| activities | hiking | Hiking | outdoors | +| choices | + +## Adding dynamic choice filters + +Choice filters can also be used to filter a choice list based on a previous response. In this case, you will have a **parent question** with a corresponding **parent list** of choices, and a **child question** with a corresponding **child list** of choices. The choice list for the child question is filtered based on the response to the parent question. + +

+For an example of an XLSForm using dynamic choice filters, see this sample form. +

+ +To add dynamic choice filters in XLSForm: +1. Add the **parent** and **child question** to your XLSForm and [define their option choices](https://support.kobotoolbox.org/option_choices_xls.html) in the `choices` worksheet. + - These must be `select_one` or `select_multiple` questions. +2. In the `choices` worksheet, add a filter column. + - It can be helpful to name this column the same as the **parent question.** +3. In the filter column, enter the **name of the choice** from the parent list that each option in the child list corresponds to. +4. In the `survey` worksheet, add a **choice_filter** column. This column will contain the **choice filter expression** used to filter the option choices. + - If the parent question is `select_one`, the choice filter expression will be `filter_column = ${question_name}`, where `question_name` refers to the parent question. + - If the parent question is `select_multiple`, the choice filter expression will be `selected(${question_name}, filter_column)`. + +When a respondent selects an option in the parent question, the choice list for the child question will be filtered to only include the corresponding choices. + +### Example + +In the example below, `continent` is the **parent question** and `country` is the **child question.** The choice list for the `country` question will be filtered based on the response to the `continent` question. + +**survey worksheet** + +| type | name | label | choice_filter | +|:------------------|:---------|:----------|:--------------------| +| select_one continent | continent | Continent | | +| select_one country | country | Country | **continent = ${continent}** | +| survey | + +**choices worksheet** + +| list_name | name | label | continent | +|:-----------|:---------|:--------|:----------| +| continent | africa | Africa | | +| continent | asia | Asia | | +| country | malawi | Malawi | africa | +| country | zambia | Zambia | africa | +| country | india | India | asia | +| country | pakistan | Pakistan| asia | +| choices | + +## Advanced choice filters in XLSForm + +You can create more advanced choice filters by using logical operators, mathematical operators, functions, and regex in your choice filter expressions. This allows for highly customized and precise filtering of options, tailoring the form to specific data collection requirements and respondent characteristics. + +

+Note: In advanced choice filter expressions, the name column of the choices worksheet can be used as a filter column. +

+ +Examples of advanced choice filter expressions in XLSForm include: +| Choice filter | Description | +|:---------------|:------------| +| `selected(${parent_question}, name)` | Display only responses that were selected in a previous `parent_question`. | +| `filter = 'outdoors' and include = 'yes'` | Combine choice filter expressions so both conditions must apply for the choice to be displayed. | +| `name != 'none'` | Exclude the None option from a choice list. | +| `selected(${Q1}, name) or name='none'` | Include choices selected in a previous question as well as a None option (even if not selected previously). | +| `filter=${Q1} or name='other'` | Include choices based on a previous question as well as an Other option. | +| `filter=${Q1} or always_include='yes'` | Include choices based on a previous question as well as a set of options that should always be included. | +| `filter <= ${product_count}` | Use numbers in the filter column instead of text, and filter based on a number from a previous question or calculation. | +| `if(${relationship_status} = 'married', filter = 'married', filter = 'unmarried')` | Use if-statements to conditionally display choices based on the respondent’s background. | + +

+ To learn more about building form logic expressions in XLSForm, see Introduction to form logic in XLSForm. +

+ +### Example +In the example below, the underlying choice list for `Q1` and `Q2` is the same, but only the options selected in `Q1` will be displayed to respondents when answering `Q2`. + +**survey worksheet** + +| type | name | label | choice_filter | +|:------------------|:-----|:--------------------------------------------------|:-------------------------| +| select_multiple item | Q1 | Which household items do you currently own? | | +| select_multiple item | Q2 | Which of these items would you consider upgrading in the future? | selected(${Q1}, name) | +| survey | + +**choices worksheet** + +| list_name | name | label | +|:----------|:----------|:----------------| +| item | fridge | Refrigerator | +| item | tv | Television | +| item | fan | Ceiling fan | +| item | microwave | Microwave oven | +| item | radio | Radio | +| item | bike | Bicycle | +| item | phone | Mobile phone | +| item | laptop | Laptop computer | +| choices | + +In the resulting form, `Q2` will display only the options chosen in `Q1`, as shown below. + +![Choice filters](images/choice_filters_xls/choice_filters.png) + +## Troubleshooting + +
+ Form slows or crashes with very long lists + Large choice lists which include thousands of rows may work in preview but fail when deployed. This happens because browser preview can handle large lists, while the mobile app or XLS parser cannot. To fix this, move large lists to an external CSV file and use select_from_file questions with choice filters. This approach is recommended for lists with more than 3,000 options. +
+ +
+ +
+ Duplicate option names in a list + If your choice list includes duplicate option names (for example, if the same neighborhood name is present in different cities), enable choice duplicates in the settings worksheet by setting allow_choice_duplicates to yes. +
+ + + diff --git a/source/constraints_xls.md b/source/constraints_xls.md new file mode 100644 index 000000000..6236583cd --- /dev/null +++ b/source/constraints_xls.md @@ -0,0 +1,107 @@ +# Adding constraints in XLSForm + +Constraints, also known as validation criteria, are a type of form logic used to **restrict the acceptable responses to a question based on a predefined condition**. If the constraint condition is not met, a customizable error message is displayed, prompting the form user to enter a valid response. + +

+ To learn more about form logic in XLSForm, see Introduction to form logic in XLSForm. +

+ +This article covers the following topics: +- Adding constraints to questions in XLSForm +- Combining multiple constraint conditions +- Customizing constraint error messages +- Advanced constraints in XLSForm + +

+ Note: This article focuses on adding constraints in XLSForm. To learn about adding constraints in the KoboToolbox Formbuilder, see Adding validation criteria in the Formbuilder. +

+For hands-on practice with adding constraints in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Adding a constraint + +Constraints are built using [question references](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing), [comparison operators](https://support.kobotoolbox.org/form_logic_xls.html#mathematical-and-comparison-operators), and constants. Constraint conditions must be met to validate or submit a form. Otherwise, an **error message** appears, and users are prevented from moving to the next page or submitting the form. + +To add constraints in XLSForm: +1. Add a **constraint** column to the `survey` worksheet. +2. In the `constraint` column, define the condition that must be met **for the response to be valid.** + - Use a period `.` to reference the question in the row where you are adding a constraint. + - Use a [comparison operator](https://support.kobotoolbox.org/form_logic_xls.html#mathematical-and-comparison-operators), followed by a reference value, to build a simple constraint. + - For example, `. > 18` restricts an `integer` question to accept only values greater than 18. + +**survey worksheet** + +| type | name | label | constraint | +|:---------|:-----------|:-------------------------------------|:----------------| +| integer | age | What is your age? | . >= 18 | +| integer | household | How many people live in your household? | . <= 30 | +| integer | income | Out of those, how many earn income? | . <= ${household} | +| survey | + +### Formatting reference values +The reference value in a constraint condition must match the **type** of the question for which you are adding a constraint. The reference value formats for main question types are listed below: + +| Question type | Reference value format | Example | +|:----------------|:-----------------------------------------------------------|:------------------------------| +| integer | Number | `. > 35` | +| select_one | Choice name (as defined in the choices worksheet) in quotation marks | `. = 'yes'` | +| select_multiple | Choice name combined with the `selected()` function | `selected(., 'chair')` | +| date | Date in the `date('YYYY-MM-DD')` format | `. > date('2021-01-01')` | +| text | Text in quotation marks (rarely used for constraints) | `. != 'Not applicable'` | + +

+ To learn more about building form logic expressions in XLSForm, see Introduction to form logic in XLSForm. +

+ +## Combining multiple constraint conditions +Multiple constraint conditions can be combined into a single expression to determine whether a response is valid. Conditions can be combined using **and**, **or**, and **not** logical operators: + +- Use **and** when all conditions must be met for a response to be valid. + - For example: . > 18 and . < 65 +- Use **or** when at least one condition must be met for a response to be valid. + - For example: . < 18 or ${student} = 'yes' +- Use **not** to indicate that a condition or set of conditions must not be met (e.g., when two conditions cannot be true together for a response to be valid). + - For example: not(. < 18 and ${household_head} = 'yes') + +**survey worksheet** + +| type | name | label | hint | constraint | +|:---------|:-------|:------------------|:--------------------------------------------|:---------------------------------------------------------| +| integer | age | What is your age? | Must be less than 18 or above 65 to participate | . < 18 or . > 65 | +| integer | weight | How much do you weigh? | Must be between 30 and 200 kg | . >= 30 and . <= 200 | +| survey | + + +## Customizing constraint error messages + +By default, when a response value in the form does not meet the constraint condition, a “Value not allowed” error message appears. It is recommended to customize this message to inform users why the value is invalid, allowing them to correct their input. + +To customize the constraint error message: +1. Add a **constraint_message** column to the `survey` worksheet. +2. In the `constraint_message` column, enter the text you wish to display as the error message when the constraint conditions are not met. + +**survey worksheet** + +| type | name | label | constraint | constraint_message | +|:--------|:-----|:----------------|:-----------|:----------------------| +| integer | age | What is your age? | . >= 18 | Must be older than 18. | + +## Advanced constraints in XLSForm + +Beyond basic constraints, you can customize conditions to ensure data quality and adapt to many data collection scenarios. To build more advanced constraint conditions in XLSForm: + +- Use parentheses to combine more than two conditions +- Use [functions](https://support.kobotoolbox.org/functions_xls.html) for increased flexibility +- Use [regular expressions](https://support.kobotoolbox.org/restrict_responses.html) to restrict text responses + +Examples of more advanced validation criteria include: + +| Criteria | Description | +|:---------|:------------| +| (. >= 18 and . < 130) or (. = 999) | The response must be between 17 and 130 or be equal to 999 (often used for non-response) | +| not(${in_university} = 'yes' and . < 16) | If the answer to `in_university` is ‘yes’, the current response must be greater than 16. | +| not(selected(., 'none') and count-selected(.)>1) | The ‘none’ option cannot be selected if any other response in a `select_multiple` question is selected. | +| . < today() | The date entered must be before today’s date. | +| regex(., '^\d{2}$') | The input is restricted to two numbers (using regular expressions). | + + diff --git a/source/edit_forms_excel.md b/source/edit_forms_excel.md index f69d316d8..55babf666 100644 --- a/source/edit_forms_excel.md +++ b/source/edit_forms_excel.md @@ -1,19 +1,72 @@ -# Editing Forms in Excel using XLSForm -**Last updated:** 15 Feb 2022 +# Introduction to XLSForm +KoboToolbox relies on [XLSForm](http://xlsform.org/en/), a standard for designing electronic forms in Excel or other spreadsheet programs. XLSForm makes it easier to manage complex forms, such as those with long choice lists or multiple translations. While the [KoboToolbox Formbuilder](https://support.kobotoolbox.org/formbuilder.html) offers an intuitive, user-friendly interface, XLSForm is recommended when working with advanced functionalities or complex forms. -KoboToolbox is building its forms using a widely shared standard called -[XLSForm](http://xlsform.org/en/). XLSForm makes it possible to create very -complex electronic forms in Excel (or any other spreadsheet program). +All forms in KoboToolbox are fully compatible with XLSForm. This means you can easily import and export your forms across KoboToolbox and other data collection platforms. XLSForm provides a standardized format for form development using common spreadsheet software, making it a practical option for collaboration and sharing. -All forms created with KoboToolbox can be imported from or exported to XLSForm -files. This means they are fully compatible with other related tools such as -[ODK](https://opendatakit.org) or [Formhub](https://formhub.org). +This article covers the following topics: -Editing a form in Excel can be an easy way to quickly make several changes to a -form (for example for translating an entire form). +- Benefits of using XLSForm for form development +- Overview of using XLSForm with KoboToolbox +- Additional resources for learning XLSForm -The XLSForm format is wonderfully documented [here](http://xlsform.org/en/). +![image](/images/edit_forms_excel/sample_xlsform.png) + +

+ This article provides an introduction to XLSForm. To get started with building XLSForms, see Getting started with XLSForm. +

+ For hands-on practice with form development using XLSForm, see KoboToolbox Academy’s online XLSForm Fundamentals Course. +

+ +## Benefits of using XLSForm + +XLSForm provides numerous benefits for building both simple and complex data collection forms. + +### Efficient form building and editing + +XLSForm leverages familiar spreadsheet features for efficient form creation and modification. You can use Excel formulas and functionalities such as copy-pasting, dragging, Find and Replace, sorting, and filtering to quickly build and manage large forms. + +### Choice list management for multiple choice questions + +XLSForm makes it easy to create and manage [choice lists](https://support.kobotoolbox.org/option_choices_xls.html). You can copy long lists directly from external sources, reuse the same options across multiple questions, or duplicate them across forms, saving time, ensuring consistency, and reducing manual errors. + +### Version control and collaboration + +XLSForm simplifies sharing and managing form versions. As forms are Excel or Google Sheets files, teams can collaborate on them in real-time, share them for review, and maintain version records. + +### Form customization + +XLSForm allows you to fully tailor your forms to different needs. You can add and manage [multiple translations](https://support.kobotoolbox.org/language_xls.html) directly in your XLSForm to support multilingual data collection. You can easily set up complex form structures, such as [question groups](https://support.kobotoolbox.org/grouping_questions_xls.html) or [repeating sections](https://support.kobotoolbox.org/repeat_groups_xls.html). Additionally, you can connect your form to [external data sources](https://support.kobotoolbox.org/pull_data_kobotoolbox.html) and [other KoboToolbox projects](https://support.kobotoolbox.org/dynamic_data_attachment.html). + +### Advanced functionalities + +XLSForm makes it easier to use advanced form building functionalities, such as [skip logic](https://support.kobotoolbox.org/skip_logic_xls.html), [calculations](https://support.kobotoolbox.org/calculations_xls.html), and [constraints](https://support.kobotoolbox.org/constraints_xls.html). As an open standard, XLSForm also offers access to features that may not yet be supported by the KoboToolbox Formbuilder. + +## Using XLSForm with KoboToolbox + +XLSForm seamlessly integrates with KoboToolbox for form building, previewing, editing, and deployment for data collection. + +Users can begin in the KoboToolbox Formbuilder by creating a new form and adding questions, then [download their form](https://support.kobotoolbox.org/xlsform_with_kobotoolbox.html#downloading-an-xlsform-from-kobotoolbox) as an XLSForm for further customization. This provides a structured foundation, which can be useful for new projects or users with less form building experience. + +Forms created in XLSForm can then be uploaded to KoboToolbox for previewing, testing, editing, and deployment. Forms can be reviewed for errors and easily modified in KoboToolbox, such as changing the title or settings. + +

+ For more information, see Using XLSForm with KoboToolbox. +

+ +## Additional XLSForm resources + +Numerous resources are available to help learn XLSForm and troubleshoot issues. + +KoboToolbox offers the following resources: + +- [KoboToolbox Help Center](https://support.kobotoolbox.org): An extensive documentation library with support articles about KoboToolbox and XLSForm. +- [KoboToolbox XLSForm Fundamentals Course](https://academy.kobotoolbox.org/courses/xlsform-fundamentals): An online course developed by our team of experts, which covers a range of skills including creating an XLSForm from scratch, using form logic and calculations, and testing and deploying forms for data collection with KoboToolbox. +- [KoboToolbox Community Forum](https://community.kobotoolbox.org): A space to connect with our global user community, to get help with custom form building or troubleshooting, and to share KoboToolbox resources. + +External resources include: + +- [XLSForm documentation](https://xlsform.org/en/): An extensive documentation website dedicated to XLSForm. +- [XLSForm Reference and Template](https://xlsform.org/en/ref-table/): A detailed resource for creating and styling forms, including question types, appearances, and optional columns. +- [ODK documentation](https://docs.getodk.org/form-reference/): Another extensive documentation website dedicated to XLSForm. -When using XLSForm, you can create complex questions and forms, which are -introduced in this site. diff --git a/source/form_logic_xls.md b/source/form_logic_xls.md new file mode 100644 index 000000000..affddfad9 --- /dev/null +++ b/source/form_logic_xls.md @@ -0,0 +1,101 @@ +# Introduction to form logic in XLSForm + +Form logic controls the flow and behavior of your form based on responses to previous questions. It allows you to create dynamic forms that adapt to user input. For example, you can use form logic to display specific questions only when relevant, validate responses, or perform calculations automatically. + +Key types of form logic include: +- **Skip logic:** Controls when questions are shown or hidden based on previous responses. +- **Constraints:** Validate responses to ensure they meet defined rules or criteria. +- **Choice filters:** Display only relevant answer options based on earlier responses. +- **Calculations:** Automatically generate values using mathematical or logical expressions. +- **Required logic:** Defines when a question must be answered. + +Form logic is built using **expressions**, which combine **question references**, **operators**, **functions**, and **constants**. The expression evaluates as TRUE or FALSE to control the form's behavior. + +

+ This article introduces the basic components of form logic in XLSForm, including question referencing, operators, and functions. To learn more about each type of form logic, see support articles on skip logic, required logic, constraints, choice filters, and calculations in XLSForm. +

+ +## Question referencing + +Question referencing allows you to incorporate the answer to a previous question into the label or logic of a subsequent question. Question referencing is frequently used in advanced forms: + +- **In question labels or hints:** For example, you can include a respondent’s child’s name in later questions about their child. +- **In form logic:** For example, you can show or hide a question based on a previous response, or validate an answer by comparing it with an earlier one. + +Question referencing uses the format **${question_name}**, where `question_name` is replaced with the unique name of the referenced question. + +If a question reference includes a spelling error or is otherwise incorrect, an error message will appear when previewing or submitting the form. + +

+ Note: When referencing a question within its own logic (i.e., in its own row), a period . can be used as a shortcut. +

+ +**survey worksheet** + +| type | name | label | constraint | +|:-----------|:-----------------|:------------------------------------------------------------------------|:--------------------------| +| integer | household_size | How many people live in your household? | | +| integer | total_under18 | Out of the ${household_size} people, how many are under the age of 18? | . < ${household_size} | +| survey | + +## Mathematical and comparison operators + +**Mathematical operators** are used to perform arithmetic calculations using numerical values in the form. Mathematical operators in XLSForm include: + +| Operator | Description | +|:-----------|:---------------------------------| +| `+` | Addition | +| `-` | Subtraction | +| `*` | Multiplication | +| `div` | Division | +| `mod` | Modulo (remainder of a division) | + +**Comparison operators** are used to compare values. Comparison operators in XLSForm include: + +| Operator | Description | +|:-----------|:------------------------------| +| `=` | Equal to | +| `>` | Greater than | +| `<` | Less than | +| `>=` | Greater than or equal to | +| `<=` | Less than or equal to | +| `!=` | Not equal to | + +## Combining conditions using logical operators + +**Logical operators** can be used in XLSForm to combine multiple conditions. Logical operators in XLSForm include: +- **and** (all conditions must be met) +- **or** (at least one of the conditions must be met) +- **not** (condition(s) must not be met) + +**survey worksheet** + +| type | name | label | constraint | +|:-----------|:----------------|:--------------------------------------|:------------------------------------| +| integer | household_size | How many people live in your household? | | +| integer | total_under18 | How many are under the age of 18? | . < ${household_size} and . >= 0 | +| survey | + +## Functions + +Functions are predefined operations used to perform calculations or manipulate data in XLSForm. Functions make calculations and form logic more efficient by automatically performing complex tasks like rounding values, calculating powers, or extracting the current date. + +

+For a comprehensive list of functions in XLSForm, see Using functions in XLSForm. +

+ +## Regex + +A regular expression (regex) is a search pattern used to match specific characters within a string. It is widely used to validate, search, extract, and restrict text in most programming languages, including in KoboToolbox. + +Regex can be used in **constraints** to control the length and characters entered into a question (e.g., limiting phone number entry to exactly 10 digits, controlling the format of ID numbers, or verifying valid email entry). It can also be used in **calculations** and other form logic. + +In KoboToolbox, regular expressions are evaluated using the function `regex(., ' ')`, where the regex is entered between apostrophes and the period `.` represents the current question. `regex(., ' ')` returns TRUE if the regular expression is met, and FALSE otherwise. + +

+ To learn more about using regex in KoboToolbox, see Restricting text responses with regular expressions. +

+ + + + diff --git a/source/form_settings_xls.md b/source/form_settings_xls.md new file mode 100644 index 000000000..dd7080ab1 --- /dev/null +++ b/source/form_settings_xls.md @@ -0,0 +1,38 @@ +# Form settings in XLSForm + +XLSForm allows you to configure settings for your forms using the `settings` worksheet. For example, you can specify a form title, set a default language, or track version numbers. + +This article covers how to add and utilize the available form settings in XLSForm. + +

+Note: This article focuses on form settings forms in XLSForm. To learn about configuring form settings in the KoboToolbox Formbuilder, see Form settings and metadata. +

+ +## Adding form settings in XLSForm + +To add form settings in XLSForm: +1. Add a `settings` worksheet to your XLSForm. +2. Create a new column for each setting, using the exact column name shown [in the table below](https://support.kobotoolbox.org/form_settings_xls.html#available-form-settings-in-xlsform). +3. Under each setting, specify the relevant value (see example below). + +**settings worksheet** + +| form_title | version | default_language | style | +|:----------------------|:--------|:----------------|:------| +| Form settings in XLSForm | v3 | English (en) | pages | +| settings | + +## Available form settings in XLSForm + +Available form settings in XLSForm include: + +| Form setting | Description | +|:----------------------------|:------------| +| form_title | Specifies the title of the form that is shown to users. This can also be set and managed in KoboToolbox when the form is uploaded. | +| version | Includes a string that represents the current version of the XLSForm (e.g., v1 or YYYYMMDD). Useful for tracking form versions for collaboration. | +| instance_name | Specifies a unique name for each form submission using fields filled in by the user during the survey. Appears in the data table for each submission. Can be used to create custom participant or submission IDs.

For example, concat(${lname}, '-', ${fname}, '-', today()) returns lastname-firstname-date. | +| default_language | Sets the default language in translated forms. The language (code) format is used, as defined in the IANA language registry website. | +| style | Specifies an alternative theme for Enketo web forms. | +| allow_choice_duplicates | Allows an XLSForm to reuse duplicated option names within a choice list (e.g., when using choice filters where choice names are duplicated). | +| public_key | Specifies the public key for encryption-enabled forms. | + diff --git a/source/form_style_xls.md b/source/form_style_xls.md new file mode 100644 index 000000000..08df77559 --- /dev/null +++ b/source/form_style_xls.md @@ -0,0 +1,91 @@ +# Styling your forms using XLSForm + +With KoboToolbox, you can customize the appearance of your forms and questions to highlight key information and adapt the layout to your data collection needs. This includes applying themes to Enketo web forms, adding headers and lists in note questions, and using color or bold formatting for emphasis. + +This article covers themes for Enketo web forms as well as styling options for notes and questions within a form. + +

+Note: This article focuses on styling forms in XLSForm. To learn about setting Enketo themes in the KoboToolbox Formbuilder, see Using alternative Enketo web form styles. +

+ +## Themes for Enketo web forms + +Enketo themes allow you to customize the appearance and layout of [Enketo web forms](https://support.kobotoolbox.org/enketo.html). Themes apply only to Enketo web forms and are not visible in KoboCollect. + +### Adding themes in XLSForm + +To add a theme in XLSForm: +1. Add a **style** column in your `settings` worksheet. +2. Specify the theme you want to use, using the exact name shown in the table below. + +**settings worksheet** + +| style | +|:------------| +| theme-grid | +| settings | + +

+Note: Themes can be combined by entering both themes in the same cell of the style column, separated by a space (e.g., theme-grid pages). +

+ +### Available themes for Enketo web forms + +The following themes are available to customize your forms: + +| XLSForm theme | Description | Preview | +|:-----------------------------|:----------------------------------------------------------------------------|:--------| +| Default theme | Displays questions one after another, on a single page. | ![Default style](images/form_style_xls/theme_default.png) | +| pages | Displays one question per screen or a group of questions together on the same screen, similar to the KoboCollect layout. | ![Pages style](images/form_style_xls/theme_pages.png) | +| theme-grid | An alternative display that is more compact, similar to paper forms, and efficiently uses space, arranging multiple questions per row. Questions are capitalized by default. Requires setting up your XLSForm. | ![Theme-grid](images/form_style_xls/theme_grid.png) | +| theme-grid no-text-transform | Same as theme-grid, but without automatic capitalization of questions. | ![Theme-grid no-text-transform](images/form_style_xls/theme_grid_no_text_transform.png) | + +### Setting up an XLSForm for theme_grid + +In Enketo web forms, the `theme_grid` layout allows you to display questions in multiple columns, making your form more compact and visually organized. The set-up of these columns, including how many there are and how wide each one should be, is controlled by assigning `w-values` to each question inside the **appearance** column of your XLSForm. + +

+ For a comprehensive overview of using theme_grid in XLSForm, see this Grid Theme Tutorial and sample XLSForm. +

+ +Before assigning `w-values` to each question, start by placing all questions into [question groups](https://support.kobotoolbox.org/grouping_questions_xls.html). The default width for a group or repeat is four columns (`w4`), so a group with `w4` can hold a maximum of four `w1` questions in a single row. A question's `w-value` is relative to its group's `w-value`. + +To specify the relative width of each question within a row: +1. Add an **appearance** column in your `survey` worksheet. +2. For each question, assign appearance values (e.g., `w1`, `w2`, `w3`) to specify its relative width within a row. +3. Modify the group width if needed using the same approach. + +Rows will always automatically expand to the full width of the page. For example, a row containing one question with an appearance value of `w2` and another with `w1` will divide the row into two-thirds and one-third, respectively. + +

+Note: Apply w-values only to top-level groups or repeats. Although applying them to nested groups or repeats is supported, it may not display well. +

+ +## Styling text + +You can use Markdown and HTML in XLSForm to **style text**, **add emphasis** with bold or italics, **create headers** of different sizes, **change fonts and colors**, and **add clickable web links**. Text styling can be applied to questions, notes, and choice labels. + +

+Note: Some styling features may not be supported in KoboCollect or Enketo. It is recommended to preview your forms in your chosen data collection method to confirm that all styling features are fully supported. +

+ +Text styling features in XLSForm include: +| Feature | Formatting | +|:---------------|:-----------| +| Italics | `*italics*` or `_italics_` | +| Bold | `**bold**` or `__bold__` | +| Hyperlink | `[name of link](url)` | +| Headers | `# Header 1` (biggest) to `###### Header 6` (smallest) | +| Bullet lists | - This is an unordered list
- in markdown | +| Numbered lists | 1. This is a numbered list
2. in markdown | +| Emojis | For example, 🙂 😐 🙁 😦 😧 😩 😱 | +| Superscript | `100 m2` turns into 100 m² | +| Subscript | `H2O` turns into H₂O | +| Colored text | `orange` turns into orange
`red` turns into red | +| Font | `cursive` turns into cursive
`red and cursive` turns into red and cursive| +| Align center | `

Centered label

` centers the text on the screen | + +

+Note: Use the \ character before #, *, _, and \ to prevent special styling effects from being triggered by these characters. +

+ diff --git a/source/functions_xls.md b/source/functions_xls.md new file mode 100644 index 000000000..7dbed7af2 --- /dev/null +++ b/source/functions_xls.md @@ -0,0 +1,88 @@ +# Using functions in XLSForm + +Functions are predefined operations used to perform calculations or manipulate data in XLSForm. They are essential for automating tasks and deriving key insights in your forms, allowing you to calculate project indicators, create scoring systems, and manage dates efficiently. + +This article lists common functions used in XLSForm, including functions to manipulate numbers, strings, dates, and GPS points. + +

+ To learn more about form logic in XLSForm, see Introduction to form logic in XLSForm. To learn about functions specifically used in repeat groups, see Repeat groups in XLSForm. +

+ +## Commonly used functions in XLSForm + +The following functions are some of the most frequently used in XLSForm. They help control form behavior, manage responses, and perform basic calculations or logical operations across questions. These functions can be applied in calculations, constraints, relevance conditions, and other expressions throughout your form. + +| Function | Description | +|:-----------|:-------------| +| `if(expression, then, else)` | If the expression is TRUE, returns `then`. If not, returns `else`. | +| `selected(${question_name}, option_name)` | Used to determine if a specific choice was selected in a `select_multiple` question. | +| `random()` | Returns a random number between 0.0 (inclusive) and 1.0 (exclusive). | +| `count-selected(${question_name})` | Returns the number of options selected in a `select_multiple` question. | +| `coalesce(${question1}, ${question2})` | Returns the first non-empty value of the two arguments. Returns an empty string if both are empty or non-existent. | +| `jr:choice-name(choice_name, '${question_name}')` | Returns the label value, in the active language, associated with the `choice_name` in the list of choices for a select type question. To retrieve the label of whichever response was selected, use `jr:choice-name(${question_name}, '${question_name}')`. | +| `selected-at(${question_name}, n)` | Returns a selected choice in a `select_multiple` question at the nth position. For example, `selected-at(${question_name}, 2)` returns the second choice selected in a `select_multiple` question. | +| `once(expression)` | Evaluates an expression only once (e.g., to ensure a random number is only generated once, or to store the first value entered for a question even if the response is changed later). | +| `instance('list_name')/root/item[name = ${question}]/column_name` | Retrieves a value from the choices sheet. Searches the choice list named `list_name`, finds the row where the choice `name` matches the response to `${question}`, and returns the value from the column specified as `column_name`. | + +## Functions to manipulate numbers + +The following functions are used to perform mathematical operations or transform numeric values in XLSForm. They can help you calculate, round, or convert numbers, as well as apply more advanced mathematical expressions when needed. + +| Function | Description | +|:---------|:------------| +| `int(number)` | Transforms a decimal number into an integer without rounding. | +| `round(number, places)` | Rounds a decimal value to a predetermined number of decimal places. | +| `pow(number, power)` | Calculates the power of a number. | +| `number(x)` | Converts x (a string or boolean expression) to a number value. | +| `log(number)`
`log10(number)` | Returns the natural log or base-10 log of a number. | +| `abs(number)` | Returns the absolute value of a number. | +| `sin(number)`
`asin(number)`
`cos(number)`
`acos(number)`
`tan(number)`
`atan(number)` | Returns the sine/arc sine, cosine/arc cosine, or tangent/arc tangent of a number. | +| `sqrt(number)` | Returns the square root of a number. | +| `exp(x)`
`exp10(x)` | Returns e^x or 10^x. | +| `pi()` | Returns an approximation of the mathematical constant π. | + +

+ Note: Inside these functions, either constants or question references can be included. +

+ +## Functions to manipulate strings + +The following functions are used to create, modify, or analyze text strings in XLSForm. They are useful for combining text, checking for specific patterns or characters, and cleaning or formatting text inputs. + +| Function | Description | +|:---------|:------------| +| `concat()` | Concatenates one or more arguments (separated by commas) into a single string. | +| `regex(string, expression)` | Returns `True` if the string is an exact and complete match for a regular expression. | +| `contains(string, substring)` | Returns `True` if the string contains the substring. | +| `starts-with(string, substring)` | Returns `True` if the string begins with the substring. | +| `ends-with(string, substring)` | Returns `True` if the string ends with the substring. | +| `substr(string, start[, end])` | Returns the substring of `string` beginning at the index start and extending to (but not including) index end (or to the termination of `string`, if end is not provided). | +| `substring-before(string, target)` | Returns the substring of `string` before the first occurrence of the target substring. If the target is not found, or `string` begins with the target substring, then this will return an empty string. | +| `substring-after(string, target)` | Returns the substring of `string` after the first occurrence of the target substring. If the target is not found this will return an empty string. | +| `translate(string, fromchars, tochars)` | Returns a copy of string, where every occurrence of a character in `fromchars` is replaced by the corresponding character in `tochars` (e.g., replacing all lowercase letters with uppercase letters).

Note: If `fromchars` is longer than `tochars`, every occurrence of a character in `fromchars` that does not have a corresponding character in `tochars` will be removed. | +| `string-length(string)` | Returns the number of characters in `string` (e.g., to add a word limit to a text question). | +| `normalize-space(string)` | Returns a string in which any leading and trailing whitespaces in the string are removed, and sequences of whitespaces are replaced with a single space. | + +## Functions to manipulate dates + +The following functions are used to record, format, and calculate date and time values in XLSForm. They can help capture the current date or time, convert text into date format, or display dates and times in a specific format. + +| Function | Description | +|:---------|:------------| +| `today()` | Returns the current date without a time component. | +| `now()` | Returns the current date and time in ISO 8601 format, including the timezone. | +| `date('YYYY-MM-DD')` | Forces dates into the correct date format (especially for dates before 1970). | +| `format-date(date, format)` | Returns `date` as a string formatted as defined by format. Common formats include: | +| `format-date-time(datetime, format)` | Returns `datetime` as a string formatted as defined by format. Common formats include: | + + +## Functions to manipulate GPS data + +The following functions are used to work with geographic data collected through GPS questions in XLSForm. They can calculate distances, perimeters, or areas based on geopoint, geotrace, or geoshape responses. + +| Function | Description | +|:---------|:------------| +| `area(${geoshape})` | Returns the area, in square meters, of a `geoshape` value. | +| `distance(geo)` | Returns the distance, in meters, of either: | +| `geofence(${geopoint}, ${geoshape})` | Returns `TRUE` if the specified ${geopoint} is inside the specified ${geoshape}, `FALSE` otherwise. Supported only in KoboCollect. | + diff --git a/source/getting_started_xlsform.md b/source/getting_started_xlsform.md index 7b6d2cbf2..2341dbe87 100644 --- a/source/getting_started_xlsform.md +++ b/source/getting_started_xlsform.md @@ -1,209 +1,181 @@ # Getting started with XLSForm -**Last updated:** 10 Jun 2025 + -When creating survey forms for KoboToolbox, you can build your form with the KoboToolbox Formbuilder or in XLSForm. XLSForm is very effective for creating both basic and advanced forms in a user-friendly format. -This article explains how to: - -- Set up an XLSForm using Microsoft Excel -- Upload and preview an XLSForm in KoboToolbox -- Download a form created with the KoboToolbox Formbuilder as an XLSForm - - - -
+When creating survey forms with KoboToolbox, you can build your form with the [KoboToolbox Formbuilder](https://support.kobotoolbox.org/formbuilder.html) or using XLSForm. XLSForm is very effective for creating both basic and advanced forms in a user-friendly format.

- Note: Some XLSForm features are not currently available in the Formbuilder, but they can be used for form building in XLSForm and then uploaded to KoboToolbox. This can be especially useful for complex forms. + For more information about XLSForm, see Introduction to XLSForm. For a comprehensive introduction to form development using XLSForm, we recommend KoboToolbox Academy’s self-paced online XLSForm Fundamentals Course.

-## What is XLSForm - -XLSForm is a standard for developing forms using Microsoft Excel and other spreadsheet software. XLSForms can then be uploaded to KoboToolbox to generate a data collection form. +This article explains how to set up an XLSForm using Microsoft Excel or other spreadsheet programs, including: -There are many advantages to using XLSForm, especially for building complex forms with more advanced functionalities, including relevance conditions, calculations, and constraints. XLSForm also enables you to collaborate on form building using the same Excel file or in real time using Google Sheets. +- Setting up the basic structure of your XLSForm +- Adding questions and option choices +- Adding form settings and optional columns +- Uploading and previewing your XLSForm in KoboToolbox

- Note: For a comprehensive introduction to form development using XLSForm, we recommend KoboToolbox Academy’s self-paced online XLSForm Fundamentals Course. + Note: Some XLSForm features are not currently available in the Formbuilder, but KoboToolbox forms can be downloaded, modified in XLSForm, and uploaded back to KoboToolbox.

+ ## Setting up an XLSForm To set up the basic structure of an XLSForm: -1. Create a workbook in Microsoft Excel or Google Sheets. +1. Create a workbook in your preferred spreadsheet software. 2. Create three worksheets: **survey**, **choices**, and **settings**. - Worksheet names must be all lowercase letters. -3. In the **survey** worksheet, create three columns with the headings: `type`, - `name`, and `label`. -4. In the **choices** worksheet, create three columns with the headings: - `list_name`, `name`, and `label`. +3. In the **survey** worksheet, create three columns with the headings: `type`, `name`, and `label`. +4. In the **choices** worksheet, create three columns with the headings: `list_name`, `name`, and `label`. 5. The **settings** worksheet is optional. It can be used to include additional form specifications and customizations. - For example: `form_title`, `style`, and `default_language`. +

+To get started with XLSForm, download a sample XLSForm here. +

+ ### Mandatory columns in XLSForm -#### Survey worksheet +The following columns are mandatory in XLSForm: + +**survey worksheet** | Column name | Description | -| :--- | :--- | +| --- | --- | | type | Defines the question type (e.g., text, integer, select_one) | | name | Defines a short, unique name to refer to each question | | label | Defines the question text as it will be displayed in the form | -#### Choices worksheet +**choices worksheet** | Column name | Description | -| :--- | :--- | +| --- | --- | | list_name | Defines the unique identifier for a list of option choices | | name | Defines a short, unique name to refer to each option choice | | label | Defines the choice text as it will be displayed in the form | ## Adding questions -In XLSForm, questions are added in the **survey** worksheet. The step-by-step process below explains how to add the following example questions: **What is your name?**, **What is your baby’s sex?**, and **How old are you?** - -1. In the `type` column of the survey worksheet, type **text**. This is the question type for the first question, **What is your name?** -2. In the `name` column, type **yourname**. This will be the unique name used to identify the first question. Each question must have a unique name and cannot contain spaces or symbols (except the underscore). -3. In the `label` column, type **What is your name?**. This label will be displayed as the question text on the form during data collection. +In XLSForm, questions are added in the **survey** worksheet. To add questions in XLSForm: -| type | name | label | -| :--- | :------- | :----------------- | -| text | yourname | What is your name? | -| survey | +1. In the `type` column of the `survey` worksheet, enter the [question type](https://support.kobotoolbox.org/question_types_xls.html) of the question you want to add. +2. In the `name` column, enter a name used to identify the question. + - Each question must have a unique name and cannot contain spaces or symbols (except underscores). +3. In the `label` column, enter the question text as it should be displayed in the form during data collection. -4. For the second question, **What is your baby’s sex?**, enter **select_one sex** in the `type` column of the survey worksheet. - - **select_one** is the question type that allows users to select only one choice from a list of response choices. - - **sex** is the name of the list of response choices, which is defined in the choices worksheet (see [Adding response choices](https://support.kobotoolbox.org/getting_started_xlsform.html#adding-response-choices)). -5. In the `name` column, type **baby_sex**. -6. In the `label` column, type **What is your baby’s sex?** +**survey worksheet** -| type | name | label | -| :------------- | :------- | :----------------------- | -| select_one sex | baby_sex | What is your baby’s sex? | +| type | name | label | +| :--- | :--- | :--- | +| text | yourname | What is your name? | | survey | +4. If you are adding **select type questions** (`select_one`, `select_multiple`, or `rank`): in the `type` column, after the question type, add a space and enter the name of the list of choices. + - The name of the list of choices is later defined in the `choices` worksheet as the `list_name`. -7. For the question **How old are you?**, follow the same process using **integer** as the question type in the `type` column. +**survey worksheet** -| type | name | label | -| :------ | :--- | :--------------- | -| integer | age | How old are you? | +| type | name | label | +| :--- | :--- | :--- | +| select_one sex | baby_sex | What is your baby’s sex? | | survey |

- Note: To learn more about question types in XLSForm, see Question types (XLSForm.org). +To learn more about question types in XLSForm, see Question types in XLSForm.

-## Adding response choices +## Adding option choices + +For select type questions, option choices are added in the **choices** worksheet. To add option choices in XLSForm: -For select type questions (**select_one** and **select_multiple**), response choice options are added in the **choices** worksheet. The step-by-step process below explains how to add the choices for the example question: **What is your baby’s sex?** +1. In the `list_name` column of the `choices` worksheet, enter the name of the **list of option choices**. + - The `list_name` is a unique identifier for a list of option choices. It must match the list name entered in the `type` column of the `survey` worksheet. +2. In the `name` column, add a short name for each option choice. + - Each choice within a list must have a unique `name`, which cannot contain spaces or symbols (except underscores). +3. In the `label` column, enter the choice text as it should be displayed in the form during data collection. -1. In the `list_name` column in the choices worksheet, enter the list_name **sex**. - - This is the list_name previously defined for the **baby_sex** question in the survey worksheet. - - The list_name is the unique identifier for the list of response choice options. -2. In the name column, add the choice name **male**. - - The choice name is the unique identifier for each choice option. -3. In the label column, enter the choice label **Male**. - - The choice label is displayed on the form during data collection. -4. To add the second choice option for the **baby_sex** question, enter **sex** in the `list_name` column. Enter **female** as the choice name and **Female** as the choice label. +**choices worksheet** -| list_name | name | label | -| :-------- | :----- | :----- | -| sex | male | Male | -| sex | female | Female | +| list_name | name | label | +| :--- | :--- | :--- | +| sex | male | Male | +| sex | female | Female | | choices | +

+To learn more about managing option choices in XLSForm, see Managing option choices in XLSForm. +

+ ## Adding settings There are many optional settings that can be added to the **settings** worksheet in XLSForm. Common form settings include: -| Form setting | Description | -| :--------------- | :------------------------------------- | -| form_title | Title displayed at the top of the form | -| default_language | Default form language | -| style | Themes for Enketo web forms | -| version | Form version ID | -| settings | +| Setting | Description | +| --- | --- | +| form_title | Title displayed at the top of the form | +| default_language | Default form language | +| style | Themes for Enketo web forms | +| version | Form version ID | For example, to add a form title: 1. Add a column in the settings worksheet named `form_title`. 2. Enter the form title in the `form_title` column. - - If you do not define a form title in your XLSForm, by default the Excel file name will be used as the project name in KoboToolbox. This can be edited in KoboToolbox.

- Note: To learn more about the settings worksheet in XLSForm, see Settings worksheet (XLSForm.org). +Note: All form settings are optional. If you do not define a form title in your XLSForm, the Excel file name will be used as the project name in KoboToolbox by default. This can be edited in KoboToolbox.

-## Adding optional columns to the survey worksheet +**settings worksheet** -To further customize your XLSForm, you can add optional columns that include form logic, question options, and advanced settings. - -| **Column name** | **Description** | -| :----------------- | :--------------------------------------------- | -| hint | Question hint | -| guidance_hint | Guidance hint | -| required | Option to make a question mandatory | -| relevant | Skip logic conditions for the question | -| constraint | Validation criteria for the question | -| constraint_message | Error message when validation criteria not met | -| appearance | Options for how questions are displayed | -| choice_filter | Criteria for cascading select | -| parameters | Settings for specific question types | -| calculation | Mathematical expression for calculate question | -| default | Default response for a question | - -## Uploading and previewing the XLSForm in KoboToolbox - -To upload and preview your XLSForm in KoboToolbox: - -1. Go to the **Project List** view in KoboToolbox and click **NEW**. -2. Select **Upload an XLSForm** and upload your **Excel** file. - - If you created your XLSForm in **Google Sheets**, you will need to download the file before uploading it to KoboToolbox. In the Google Sheets menu, click File > Download > Microsoft Excel. -3. Enter the project details and click **CREATE PROJECT**. -4. Click the **Preview** button. +| form_title | +| :--- | +| Getting started with
XLSForm | +| settings |

- Note: To learn how to import your XLSForm via URL, see the support article Importing an XLSForm via URL. +To learn more about the settings worksheet in XLSForm, see Form settings in XLSForm.

-## Downloading an XLSForm from KoboToolbox - -Forms created using the KoboToolbox Formbuilder can be easily downloaded as an XLSForm file. +## Adding optional columns to the survey worksheet -1. Go to the **FORM** tab of your project in KoboToolbox. -2. Click the **More actions** icon. -3. Click **Download XLS**. +To further customize your XLSForm, you can add optional columns to configure form logic, question options, and advanced settings. Common optional columns include: -Downloading your KoboToolbox form as an XLSForm file can be very useful for many reasons, including: +| Column name | Description | +| --- | --- | +| hint | Question hint | +| guidance_hint | Guidance hint | +| required | Option to make a question mandatory | +| relevant | Skip logic conditions for the question | +| constraint | Validation criteria for the question | +| constraint_message | Error message when validation criteria are not met | +| appearance | Options for how questions are displayed | +| choice_filter | Criteria for cascading select | +| parameters | Settings for specific question types | +| calculation | Mathematical expression for calculate question | +| default | Default response for a question | -- Adding advanced features to your form that are not currently supported in the Formbuilder. -- Making changes to the form that are more efficient to do in XLSForm (e.g., duplicating a large number of questions or adding translations). -- Avoiding slow computer or internet speeds that can affect form building in the Formbuilder (e.g., limited RAM, poor internet connectivity). -- Sharing the form as an Excel file for collaboration with team members and managing form versions. -- Sharing the form to request assistance from the KoboToolbox support team or in the Community Forum. +

+To learn more about optional columns in XLSForm, see Using question options in XLSForm, Question appearances in XLSForm, and Introduction to form logic in XLSForm. +

-## Replacing a form with an XLSForm file +## Uploading and previewing your XLSForm in KoboToolbox -You can replace an existing form in the Formbuilder with a new version using an XLSForm. For example, after editing the form in Excel, you must upload the updated file to KoboToolbox. +Once you have finished developing your XLSForm, you can upload and preview it in KoboToolbox: -1. Go to the **FORM** tab of your project in KoboToolbox. -2. Click the **More actions** icon. -3. Click **Replace form**. -4. Choose the file you wish to upload. +1. Go to the **Project** home page in KoboToolbox and click **NEW**. +2. Select **Upload an XLSForm** and upload your XLSForm file. +3. Enter the project details and click **CREATE PROJECT**. +4. Click the **Preview** button. -## More XLSForm resources +If your XLSForm contains an error, an error message will appear, usually indicating the exact row, question, or expression where the issue is located. After correcting the error in your XLSForm, you will need to upload the file again. -For more information about using XLSForm, see the following resources: +

+To learn how to download an XLSForm from KoboToolbox, import your XLSForm via URL, and use KoboToolbox to validate and test your XLSForm, see Using XLSForm with KoboToolbox. +

-- [Official XLSForm documentation at XLSForm.org](https://xlsform.org) -- [Form building documentation from ODK](https://docs.getodk.org/) diff --git a/source/grouping_questions_xls.md b/source/grouping_questions_xls.md new file mode 100644 index 000000000..bff37efc4 --- /dev/null +++ b/source/grouping_questions_xls.md @@ -0,0 +1,139 @@ +# Grouping questions in XLSForm +**Last updated:** 15 May 2025 + +Grouping questions in XLSForm helps organize related content into clear, structured sections, improving form layout and navigation. For example, you can group all demographic questions into one section. + +XLSForm makes it easy to create groups and [nested groups](https://support.kobotoolbox.org/grouping_questions_xls.html#nested-groups), and to apply [skip logic](https://support.kobotoolbox.org/grouping_questions_xls.html#applying-skip-logic-to-question-groups) to entire question groups. Group-level skip logic streamlines the respondent's experience by showing only relevant sections based on previous answers. + +This article covers the following topics: + +- Creating question groups and nested groups in XLSForm +- Displaying all grouped questions on a single page +- Adding skip logic to question groups + +

+Note: This article focuses on grouping questions in XLSForm. To learn about grouping questions in the KoboToolbox Formbuilder, see Grouping questions and repeating groups. +

+ +## Creating a question group + +To create a question group in XLSForm: + +1. In the `type` column of the `survey` worksheet, enter **begin_group** to indicate the start of the group. +2. In the `name` column of the **begin_group** row, enter the unique identifier for the group. +3. In the `label` column, enter the title of the group as you want it displayed in the form. The label is optional and can be left blank. +4. Enter each question of the group in its own row, as you normally would. +5. In a new row after the grouped questions, enter **end_group** in the `type` column to indicate the end of the group. + - In the **end_group** row, leave the `name` and `label` columns blank. + +**survey worksheet** + +| type | name | label | +| :--- | :--- | :--- | +| **begin_group** | personal_info | Section A: Personal Information | +| text | name | What is your name? | +| integer | age | How old are you? | +| select_one yn | married | Are you married? | +| **end_group** | | | +| survey | + +### Nested groups + +Nested groups are groups of questions inside another group of questions. Nested groups can be used to create a hierarchical structure within your XLSForm. For example, you can include a group of questions about a child inside a larger group of questions about the household. + +When creating multiple groups, ensure that each `begin_group` row has a corresponding `end_group` row. If the number of `begin_group` rows does not match the number of `end_group` rows, the form will generate an error, preventing it from functioning properly during preview or deployment. + +**survey worksheet** + +| type | name | label | +| :--- | :--- | :--- | +| **begin_group** | personal_info | Section A: Personal Information | +| text | name | What is your name? | +| integer | age | How old are you? | +| select_one yn | married | Are you married? | +| **begin_group** | education | Education | +| select_one yn | student | Are you currently a student? | +| select_one edu | education_level | What is the highest level of education you have completed? | +| **end_group** | | | +| **end_group** | | | +| survey | + +### Repeat groups + +In XLSForm, question groups can be repeated to collect the same set of responses multiple times within a form. This is useful when gathering similar information about multiple people, items, or events. Repeated groups are called **repeat groups**. + +

+ To learn more about setting up repeating groups of questions in XLSForm, see Repeat groups in XLSForm. +

+ +## Appearance settings for question groups + +A common reason to group questions is to display them together on a single page. You can adjust the group's appearance settings to control how grouped questions are shown during data collection. The steps vary depending on whether you are using [KoboCollect](https://support.kobotoolbox.org/kobocollect_on_android_latest.html) or [Enketo](https://support.kobotoolbox.org/enketo.html). + +

+Note: Appearance settings to display groups on a single page work both for question groups and repeat groups. +

+ +### Using KoboCollect to collect data + +By default, KoboCollect displays each question on a separate screen. Users must move manually from one question to the next. + +To **display all grouped questions on the same screen** in KoboCollect: +1. In the `survey` worksheet, add an **appearance** column. +2. In the `appearance` column, enter **field-list** in the `begin_group` row. + * Each question group will now appear on its own page. + +| type | name | label | appearance | +| :--- | :--- | :--- | :--- | +| begin_group | personal_info | Section A: Personal Information | **field-list** | +| text | name | What is your name? | | +| integer | age | How old are you? | | +| select_one yn | married | Are you married? | | +| end_group | | | | + +### Using Enketo web forms to collect data + +By default, Enketo web forms display all questions on a single page. + +To display each group of questions on its own page in Enketo web forms: +1. In the `settings` worksheet, add a **style** column. +2. In the second cell of the `style` column, enter **pages**. + * This applies the **pages** [theme](https://support.kobotoolbox.org/form_style_xls.html) to your Enketo web form, dividing it into separate pages similar to KoboCollect. + +**settings worksheet** + +| style | +| :--- | +| **pages** | +| settings | + +3. In the `survey` worksheet, add an **appearance** column. +4. In the `appearance` column, enter **field-list** in the `begin_group` row. + * Each question group will now appear on its own page. + +**survey worksheet** + +| type | name | label | appearance | +| :--- | :--- | :--- | :--- | +| begin_group | personal_info | Section A: Personal Information | **field-list** | +| text | name | What is your name? | | +| integer | age | How old are you? | | +| select_one yn | married | Are you married? | | +| end_group | | | | +| survey | + + +## Applying skip logic to question groups + +Applying skip logic to question groups ensures that only relevant sections appear based on earlier responses. For example, in a household survey, you can use skip logic to show a group of questions for the head of household only when a previous question identifies the respondent as such. This makes the form easier to navigate and more responsive to user input. + +To [apply skip logic](https://support.kobotoolbox.org/skip_logic_xls.html) to question groups in XLSForm, use the same approach as you would for individual questions: +1. Add a **relevant** column to your `survey` worksheet. +2. In the `relevant` column for the `begin_group` row, enter the condition that determines when the group should be shown. +3. If the condition is met, the entire group will be displayed. If not, the group will be hidden. + +This helps control the flow of your form so that only relevant sections appear based on earlier responses, making the form more streamlined and responsive to user input. + +

+Note: Skip logic can be applied both for question groups and repeat groups. To learn more about skip logic in XLSForm, see Adding skip logic in XLSForm. +

diff --git a/source/images/choice_filters_xls/choice_filters.png b/source/images/choice_filters_xls/choice_filters.png new file mode 100644 index 000000000..52cabe05c Binary files /dev/null and b/source/images/choice_filters_xls/choice_filters.png differ diff --git a/source/images/edit_forms_excel/sample_xlsform.png b/source/images/edit_forms_excel/sample_xlsform.png new file mode 100644 index 000000000..22621206c Binary files /dev/null and b/source/images/edit_forms_excel/sample_xlsform.png differ diff --git a/source/images/form_style_xls/theme_default.png b/source/images/form_style_xls/theme_default.png new file mode 100644 index 000000000..49d65af7d Binary files /dev/null and b/source/images/form_style_xls/theme_default.png differ diff --git a/source/images/form_style_xls/theme_grid.png b/source/images/form_style_xls/theme_grid.png new file mode 100644 index 000000000..0f6eca40c Binary files /dev/null and b/source/images/form_style_xls/theme_grid.png differ diff --git a/source/images/form_style_xls/theme_grid_no_text_transform.png b/source/images/form_style_xls/theme_grid_no_text_transform.png new file mode 100644 index 000000000..8bce43ffc Binary files /dev/null and b/source/images/form_style_xls/theme_grid_no_text_transform.png differ diff --git a/source/images/form_style_xls/theme_pages.png b/source/images/form_style_xls/theme_pages.png new file mode 100644 index 000000000..ed79f3c88 Binary files /dev/null and b/source/images/form_style_xls/theme_pages.png differ diff --git a/source/images/library_locking/locked.png b/source/images/library_locking/locked.png new file mode 100644 index 000000000..57e05157e Binary files /dev/null and b/source/images/library_locking/locked.png differ diff --git a/source/images/library_locking/upload_template.png b/source/images/library_locking/upload_template.png new file mode 100644 index 000000000..ebc04a22e Binary files /dev/null and b/source/images/library_locking/upload_template.png differ diff --git a/source/images/library_locking/use_template.png b/source/images/library_locking/use_template.png new file mode 100644 index 000000000..a9ee86318 Binary files /dev/null and b/source/images/library_locking/use_template.png differ diff --git a/source/images/media/upload_media.png b/source/images/media/upload_media.png new file mode 100644 index 000000000..c6ba28128 Binary files /dev/null and b/source/images/media/upload_media.png differ diff --git a/source/images/pull_data_kobotoolbox/upload_media.png b/source/images/pull_data_kobotoolbox/upload_media.png new file mode 100644 index 000000000..c6ba28128 Binary files /dev/null and b/source/images/pull_data_kobotoolbox/upload_media.png differ diff --git a/source/images/select_from_file_xls/upload_media.png b/source/images/select_from_file_xls/upload_media.png new file mode 100644 index 000000000..c6ba28128 Binary files /dev/null and b/source/images/select_from_file_xls/upload_media.png differ diff --git a/source/images/xlsform_with_kobotoolbox/download_xls.png b/source/images/xlsform_with_kobotoolbox/download_xls.png new file mode 100644 index 000000000..0f347e25b Binary files /dev/null and b/source/images/xlsform_with_kobotoolbox/download_xls.png differ diff --git a/source/images/xlsform_with_kobotoolbox/import_via_url.png b/source/images/xlsform_with_kobotoolbox/import_via_url.png new file mode 100644 index 000000000..09469ad4e Binary files /dev/null and b/source/images/xlsform_with_kobotoolbox/import_via_url.png differ diff --git a/source/images/xlsform_with_kobotoolbox/replace_form.png b/source/images/xlsform_with_kobotoolbox/replace_form.png new file mode 100644 index 000000000..69b6745c8 Binary files /dev/null and b/source/images/xlsform_with_kobotoolbox/replace_form.png differ diff --git a/source/images/xlsform_with_kobotoolbox/upload_xls.png b/source/images/xlsform_with_kobotoolbox/upload_xls.png new file mode 100644 index 000000000..7014c51fd Binary files /dev/null and b/source/images/xlsform_with_kobotoolbox/upload_xls.png differ diff --git a/source/index.rst b/source/index.rst index a27df47f3..d8c20fffd 100644 --- a/source/index.rst +++ b/source/index.rst @@ -102,11 +102,29 @@ Search the knowledge base, browse our resources, and visit our forum for more de edit_forms_excel getting_started_xlsform - xls_url - media + xlsform_with_kobotoolbox + question_types_xls + option_choices_xls + grouping_questions_xls + repeat_groups_xls + question_options_xls + appearances_xls language_xls - dynamic_data_attachment + media + form_logic_xls + functions_xls + skip_logic_xls + constraints_xls + required_logic_xls + choice_filters_xls + calculations_xls + form_settings_xls + form_style_xls.md + metadata_xls pull_data_kobotoolbox + select_from_file_xls + select_from_map_xls + dynamic_data_attachment library_locking .. raw:: html diff --git a/source/language_xls.md b/source/language_xls.md index ea7ebd3fc..f01ebcef1 100644 --- a/source/language_xls.md +++ b/source/language_xls.md @@ -1,132 +1,144 @@ -# Adding Another Language to your XLSForm -**Last updated:** 29 Jul 2025 +# Adding translations in XLSForm +**Last updated:** Oct 26, 2025 +Adding translations to a form allows users to switch to their preferred language during data collection without creating separate forms. Any number of translations can be added. Both [KoboCollect](https://support.kobotoolbox.org/kobocollect_on_android_latest.html) and [Enketo web forms](https://support.kobotoolbox.org/enketo.html) support form translations. -There are two methods to adding multiple languages to your form. You can either -add and manage them directly through the online -[Project Dashboard](language_dashboard.md) or you can add them in an XLSForm and -upload it to Kobo. +Most elements displayed in the form can be translated, such as **question labels**, **hints**, **choice labels**, **constraint messages**, and **required messages**. Elements used for form structure, like question names, choice names, and list names, cannot be translated and should remain in the language used for form development and data analysis. -Here are detailed instructions on how you can add another language to your form: +When your form includes multiple translations, KoboCollect and Enketo will display a language selector in the **top right corner of the form**, allowing respondents to choose their preferred language. -- Create your form in the default language. This should be the language that - the person responsible for designing the questionnaire is most comfortable - with. When you are done, or when a portion of the form has been created, - save it. You'll be returned to the draft form's project dashboard. +

+ Note: Adding translations in XLSForm is faster and more efficient than using the Formbuilder, especially for longer forms. To learn how to download your form in XLSForm to add translations, see Using XLSForm with KoboToolbox. +

+For hands-on practice with adding translations in XLSForm, see KoboToolbox Academy's XLSForm Fundamentals Course. +

-- Export the form to XLS. +## Language codes in XLSForm -- Open the file in Excel (Google Spreadsheet, Open Office Calc, etc will all - work) (If you're in Excel it's possible you have to take the file out of - Protected View first. - [See here](https://support.office.com/en-us/article/what-is-protected-view-d6f09ac7-e6b9-4495-8e43-2bbcdbcb6653?ocmsassetID=HA010355931&CorrelationId=04b441d5-5c7c-441a-bbac-8f34b3071869&ui=en-US&rs=en-US&ad=US).) - Your spreadsheet will have three sheets (see the little tabs at the bottom): - **survey**, **choices**, **settings**. Stay in the **survey** sheet for now. +When referring to different languages in XLSForm, you will need to use the format `language (code)` in your column headers. For example, the language reference for English is `English (en)` and the language reference for French is `French (fr)`. Each translation must use the same language name and code consistently throughout your form. -- Find the column called `label`. This is where your original question labels - are stored. Insert another column to the right of label. In the header - (first row) of this new column, write `label::language (code)`, for example - `label::Français (fr)` or `label::English (en)`. +Language codes can be found in the IANA language subtag registry. On the IANA website, the **Description** refers to the language name, and the **Subtag** refers to the language code (e.g., **Description:** French, **Subtag:** fr). -

You can change the size of your columns, add colors or change the font size, none of these will affect your form.

-- Then, if you have hints in your form, the same needs to apply to the `hint` - column, for example `hint::Français (fr)` or `hint::English (en)`. +## Setting the default form language -**survey sheet** +To add translations to an XLSForm, first define the default language. This is the language the form will open to by default. -| type | name | label | relevant | -| :--------------- | :------------- | :----------------------------- | :------------------------ | -| text | full_name | What is your name? | | -| select_one yesno | children_yesno | Do you have any children? | | -| integer | children_count | How many children do you have? | ${children_yesno} = 'yes' | +To define the default language of your form: +1. In the `settings` worksheet, add a **default_language** column. +2. In the `default_language` column, enter the default language using the **language (code)** format. + - For example: `English (en)`. + +**settings worksheet** + +| default_language | +| :---------------- | +| English (en) | +| settings | + +To set up the `survey` worksheet: + +1. Rename the **label** column using the format **label::language (code)**. + - For example: `label::English (en)`. +2. If your form includes `hint`, `required_message`, `constraint_message`, or `media` columns in the `survey` worksheet, rename the existing columns using the format **column_name::language (code)**. + - For example: `hint::English (en)`. + +**survey worksheet** + +| type | name | label::English (en) | hint::English (en) | +| :--- | :--- | :------------------ | :----------------- | +| integer | age | How old are you? | In years | +| select_one yn | student | Are you currently a student? | | | survey | -- Now add your translations for every row inside the `label::language (code)` - column. When you are done, make sure you didn't skip any questions (for - every field that has text inside the label column there should be text - inside the `label::language (code)` column). You can find the official - 2-character language codes (subtags) - [here](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry). +Finally, to set up the `choices` worksheet, rename the **label** column using the format **label::language (code)**. + +**choices worksheet** + +| list_name | name | label::English (en) | +| :--------- | :--- | :------------------ | +| yn | yes | Yes | +| yn | no | No | +| choices | + +## Adding translations + +Once you have defined your default language, you can add translations for each visible element of your form. You can add as many translation columns as you like. + +

+ Note: If you omit text for a translated element, it will appear as a blank field on the form. +

-

Tip: Copy-paste the original label column and then make changes to the translations so you don't leave anything blank by accident: It's better to have something showing in the wrong language than not having a blank question in some language. You can repeat this step and add as many languages as you like, each in their separate columns and with a different name inside label::language (code).

+To add translations to the `survey` worksheet: +1. Add a new **label** column for each translation language using the format **label::language (code)**. + - For example: `label::Spanish (es)`. +2. If your form includes `hint`, `required_message`, `constraint_message`, or `media` columns in the `survey` worksheet, set up the corresponding translation columns using the **column_name::language (code)** format. + - For example: `hint::French (fr)` or `required_message::Chichewa (ny)`. +3. Enter the translations for all form elements in the relevant columns. -**survey sheet** +

+ To learn more about managing media files in translated forms, see Adding media to an XLSForm. +

-| type | name | label:English (en) | label::Français (fr) | relevant | -| :--------------- | :------------- | :----------------------------- | :----------------------------- | :------------------------ | -| text | full_name | What is your name? | Quel est votre nom? | | -| select_one yesno | children_yesno | Do you have any children? | Avez-vous des enfants? | | -| integer | children_count | How many children do you have? | Combien des enfants avez-vous? | ${children_yesno} = 'yes' | +**survey worksheet** + +| type | name | label::English (en) | label::Chichewa (ny) | hint::English (en) | hint::Chichewa (ny) | +| :--- | :--- | :------------------ | :------------------- | :----------------- | :------------------ | +| integer | age | How old are you? | Muli ndi zaka zingati? | In years | M'zaka | +| select_one yn | student | Are you currently a student? | Kodi panopa ndinu wophunzira? | | | | survey | -- Now switch to the **choices** sheet of your file, if you have one. +To add translations to the `choices` worksheet: +1. Add a new **label** column for each translation language using the format **label::language (code)**. + - For example: `label::Spanish (es)`. +2. Enter the translation for each choice label in the relevant translation column. +3. If your `choices` worksheet includes media columns, set up the corresponding translation columns using the **column_name::language (code)** format. -- In the **choices** sheet you have another column called `label`. Repeat - steps 5 and 6. Make sure that you use the exact same spelling for - `label::language (code)`. For example, `label::Francais (fr)` and - `label::Français (fr)` are not identical. +

+ Note: To learn more about managing media files in translated forms, see Adding media to an XLSForm. +

-**choices sheet** +**choices worksheet** -| list_name | name | label::English (en) | label::Français (fr) | -| :-------- | :--- | :------------------ | :------------------- | -| yesno | yes | Yes | Oui | -| yesno | no | No | Non | +| list_name | name | label::English (en) | label::Chichewa (ny) | +| :--------- | :--- | :------------------ | :------------------- | +| yn | yes | Yes | Inde | +| yn | no | No | Ayi | | choices | -- In the **settings** sheet, underneath `form_title` edit the text of your - form's title to something like "My form (English and French)" so you can - easily identify it later. -**settings sheet** +## Guidelines for translations -| form_title | -| :--------------------------- | -| My form (English and French) | -| settings | +### Using spreadsheet features for bulk translations + +XLSForm makes it easy to translate form elements in bulk, instead of entering translations one by one. For example, you can copy an entire column into a translation system for bulk translation, and paste the column back into your XLSForm. If you are using Google Sheets to build your XLSForm, you can use the `GOOGLETRANSLATE()` formula to automate the translation process. + +Machine translations should always be reviewed and validated by a fluent speaker to ensure accuracy, cultural appropriateness, and proper context. This step helps maintain the quality and reliability of your translated content. + +### Translating to non-Latin scripts + +Non-Latin scripts such as Arabic, Cyrillic, Tamil, Nepali, or Hindi are fully supported in KoboToolbox and can be used for default languages or translations. -- Save your file and close Excel. - -- Return to KoboToolbox and click on **Replace with XLS**, then upload your - updated XLSForm. Choose the file you just finished editing and click **OK**. - -- Open the form you just uploaded and click on **Preview Form**. At the top - next to **Choose Language** click on the dropdown. It will have a default - (your original language) as well as the new languages you just added. - -## Translating to Tamil, Nepali, Hindi, etc. scripts - -When translating to non-Latin scripts, such as Tamil, Nepali, Hindi, etc, please -make sure you do not use a so-called pseudo font. When writing in these -languages make sure you only use the proper Unicode characters. To write proper -Unicode characters you don't have to install any particular fonts. Instead, you -(or your translator) need to set your keyboard to use the respective script -(Tamil, Nepali, etc.) and then write normally. The correct keyboard setting will -produce the actual script letters in Unicode instead of some Latin phonetic -equivalents. (This would also be the same way as writing these languages into an -email, KoboToolbox, or any other Web application. - -For help with adding the correct system keyboard, -[check this link](https://support.microsoft.com/en-us/help/17424/windows-change-keyboard-layout) -(Windows only). - -Pseudo fonts allow writing in these scripts and are commonly used in many -countries, particularly in South Asia. But while they work on the computer that -has a specific font installed, they will not work on any other computer that -doesn't use that particular font. That is because these fonts just disguise -regular Latin characters and symbols and make them appear in a different shape. -For example, when writing "Hello" with the Nepali pseudo font 'Preeti', it will -look like this: हेल्लो. But what is really written there remains the letters H e -l l o. For some people using these fonts which often use phonetic equivalents to -English, may be easier. Another reason they are being used widely is that many -computers used to not have support for these scripts and thus needed pseudo -fonts as a "hack". Either way, Unicode characters are the best way to go - and -the only way for use in KoboToolbox. +

+ Note: It is recommended to use only Latin characters for question and choice names, because non-Latin scripts may cause errors or compatibility issues when exporting data or working with XLSForm, but question and choice labels can safely use any script. +

+ +When adding translations in non-Latin scripts, it is essential to **use proper Unicode characters**. Unicode ensures that text is correctly displayed and understood across all devices and platforms. + +To enter Unicode text, you do not need to install any special fonts. Instead, set your system keyboard to the appropriate language or script and type as you normally would. Avoid using pseudo fonts (i.e., special fonts that visually mimic non-Latin scripts by reassigning Latin characters), as these are not compatible with KoboToolbox and can cause serious display and data integrity issues. If you are using Windows and need help setting up your system keyboard, refer to [Microsoft documentation](https://support.microsoft.com/en-us/windows/manage-the-language-and-keyboard-input-layout-settings-in-windows-12a10cb4-8626-9b77-0ccb-5013e0c7c7a2). ## Translating right-to-left scripts -When adding a language that uses right-to-left script it is important to use the -correct language code, however even if the correct code is used, if the first -question, hint, or note is written in a left-to-right script the form will -automatically format the rest of the translation to a left-to-right format. +When adding a language that uses a right-to-left (RTL) script, such as Arabic, Hebrew, or Urdu, it is important to **use the correct language code** and to ensure the **first visible text in the translation** (e.g., a question label, hint, or note) is written in the RTL language. This will ensure that the form's layout does not default to left-to-right (LTR) formatting. + +Additionally, when incorporating question references within question labels using RTL scripts, please note that the question reference syntax is reversed (i.e., `{question_name}$`). + +**survey worksheet** + +| type | name | label::English (en) | label::Arabic (ar) | +| :--- | :--- | :------------------ | :----------------- | +| begin\_group | profile | Respondent profile | ملف المستجيب | +| text | name | Respondent's name | اسم المدعى عليه | +| integer | age | How old is ${name}? | ؟{name}$ كم عمرك | +| end\_group | | | | +| survey | diff --git a/source/library_locking.md b/source/library_locking.md index 05c748b61..ecca622ad 100644 --- a/source/library_locking.md +++ b/source/library_locking.md @@ -1,429 +1,217 @@ -# Library locking +# Library locking with XLSForm **Last updated:** 30 Sep 2025 +The [KoboToolbox Library](https://support.kobotoolbox.org/question_library.html) allows you to store and manage templates, questions, and blocks for reuse across multiple projects. Form templates in the **Library** can be shared with team members to ensure consistent form design and reduce duplication of effort. -"Library locking" refers to the feature enabling various aspects of a survey to -be "[locked](#locked)" when created from a template containing -[locking attributes](#restrictions). All aspects of a form's editing are -available to be locked through the assigning of "[locking profiles](#profile)" -at the form, question or group level. These locking profiles can be assigned -granular "[restrictions](#restriction)" that group together locking -functionalities. Alternatively, the form can be fully locked down, preventing -all aspects of editing. +**Library locking** expands on this by allowing you to control how templates can be edited once they are used to create new projects. With locking, you can specify which questions, groups, or form-level settings can be changed. This is especially useful for large teams working from a shared template, where certain elements need to remain fixed while others can be adapted to local needs. -

- Currently, only locking set within the XLSForm itself is supported, but will - be incorporated into the formbuilder at some point in the future. -

- -This feature may be useful in a large, distributed team setting where a standard -template is used, with some locked features, and each team can make necessary -local adjustments for their needs. The creator of the template can continue to -make updates, but the locks will restrict changes to specified aspects of the -form for those who [create a project based on the template](quick_start.md). +This article explains how library locking works, the types of restrictions you can apply, how to configure them in XLSForm, and how to upload locked XLSForms to KoboToolbox.

- Locking aspects of a form is separate from - managing project permissions. +Note: Library locking is not currently supported in the KoboToolbox Formbuilder. To use this feature, you must implement it via XLSForm and then upload your XLSForm to KoboToolbox. +

+To learn more about downloading and editing your form as XLSForm, see Using XLSForm with KoboToolbox.

-## Restrictions +## Introduction to Library locking -There are three levels of restrictions that can be set: +Library locking controls how much of a form **can be edited** when a project is created from a Library template. Restrictions are defined in your XLSForm before uploading the form. -1. [Question](#question-level-restrictions), -2. [Group](#group-level-restrictions), and -3. [Form](#form-level-restrictions) +When you create a locked template and share it through your Library: +- Users can make local adjustments where restrictions allow. +- Locked elements appear **grayed out** in the Formbuilder. +- A message above the form indicates which restrictions are active. -Additionally, there is a `kobo--lock_all` boolean that can set in the `settings` -sheet that will render the survey completely locked. +Library locking is separate from [project permissions](https://support.kobotoolbox.org/managing_permissions.html), which control what different users can do inside a deployed project. -### `kobo--lock_all` boolean +

+Note: Library locking restrictions apply only in the Formbuilder when a project is created from a locked template. If the XLSForm is downloaded and edited in a spreadsheet, the restrictions will not prevent changes. However, incorrect or invalid locking configurations may cause errors when the form is re-uploaded. +

-If `kobo--lock_all` is set to `True`, then all additional granular restrictions -are redundant as the form is _fully_ locked down. If it is set to `False` _or_ -omitted from the `settings` sheet, then defined locking profiles can be used to -control the locked behaviour: +Library locking is configured in three XLSForm worksheets: +- **survey worksheet:** To apply restrictions to specific questions and groups. +- **settings worksheet:** To apply form-level restrictions and set the `kobo--lock_all` option. +- **kobo--locking-profiles worksheet:** To define profiles that group related restrictions. -**settings sheet** +Together, these worksheets let you define which parts of a form remain fixed and which parts can be edited when the template is used to create new projects. -| kobo--lock_all | -| :------------- | -| true | -| settings | +## Types of restrictions -The accepted values for `kobo--lock_all` are the same as in the `survey` sheet -that -[pyxform supports](https://github.com/XLSForm/pyxform/blob/43ea039250f44cff23b3ad10740fca54dfa12383/pyxform/aliases.py#L127-L142). -No error will be thrown if an invalid value is used, only the form will not -function as intended from the user's perspective. +Library locking supports restrictions at three levels: **question**, **group**, and **form**. Restrictions define what can and cannot be edited when a project is created from a locked template. -

- Note that the restriction name, such as choice_add below, is - predefined and only the restrictions listed below are valid - options. -

+In addition, a global setting (`kobo--lock_all`) can be used to lock the entire form. ### Question-level restrictions -| Name | Description | -| :------------------------- | :----------------------------------------------------------------- | -| `choice_add` | Add new choices to a `select_*` question | -| `choice_delete` | Remove an existing choice from a `select_*` question | -| `choice_value_edit` | Edit a choice `name` | -| `choice_label_edit` | Edit a choice `label` | -| `choice_order_edit` | Reorder the choices of a `select_*` question | -| `question_delete` | Delete a given question | -| `question_label_edit` | Edit an existing `label` or `hint` | -| `question_settings_edit` | Edit a question's settings (other than `constraint` or `relevant`) | -| `question_skip_logic_edit` | Edit a question's skip logic settings (`relevant`) | -| `question_validation_edit` | Edit a question's validation criteria settings (`constraint`) | +Question-level restrictions apply to individual questions. You can apply the following restrictions to questions in your XLSForm: +| Restriction | Description | +|:------------------------------|:---------------------------------------------------------------------------------------------------------------| +| choice_add | Prevents adding new choices to a **select** question. | +| choice_delete | Prevents deleting existing choices in a **select** question. | +| choice_value_edit | Prevents editing a choice name (or XML value). | +| choice_label_edit | Prevents editing a choice label. | +| choice_order_edit | Prevents reordering choices in a **select** question. | +| question_delete | Prevents deleting a question. | +| question_label_edit | Prevents editing a question label or hint. | +| question_settings_edit | Prevents editing question settings, including the question name. This does not include skip logic or validation criteria. | +| question_skip_logic_edit | Prevents editing skip logic conditions. | +| question_validation_edit | Prevents editing validation criteria. | ### Group-level restrictions -| Name | Description | -| :-------------------------- | :----------------------------------------------------------------------------------------------------- | -| `group_delete` | Delete group modal **Delete everything** button (or delete group button if paired with `group_split`) | -| `group_split` | Delete group modal **Ungroup questions** button (or delete group button if paired with `group_delete`) | -| `group_label_edit` | Edit a group `label` | -| `group_question_add` | Adding or cloning questions inside given group (children groups included) | -| `group_question_delete` | Delete any question from given group (children groups questions included) | -| `group_question_order_edit` | Changing order of questions inside given group (children groups included) | -| `group_settings_edit` | Changing **All group settings** from given group **Settings** | -| `group_skip_logic_edit` | Changing **Skip Logic** from given group **Settings** | +Group-level restrictions apply to [question groups](https://support.kobotoolbox.org/grouping_questions_xls.html). You can apply the following restrictions to groups in your XLSForm: + +| Name | Description | +|:------|:-------------| +| group_delete | Prevents deleting a group. | +| group_split | Prevents ungrouping questions. | +| group_label_edit | Prevents editing the group label. | +| group_question_add | Prevents adding or cloning questions inside a group. | +| group_question_delete | Prevents deleting questions from within a group. | +| group_question_order_edit | Prevents reordering questions inside a group. | +| group_settings_edit | Prevents editing group settings, including the group name. This does not include skip logic. | +| group_skip_logic_edit | Prevents editing skip logic for a group. | ### Form-level restrictions -| Name | Description | -| :-------------------- | :----------------------------------------------------------------------------------------------- | -| `form_appearance` | Changing form appearance from **Layout & Settings** | -| `form_replace` | Replacing form using **Replace Form** modal | -| `group_add` | Button for grouping questions | -| `question_add` | Using **Insert cascading select** option and each **Add Question** and **Clone Question** button | -| `question_order_edit` | Changing any questions order | -| `language_edit` | Edit languages in **Translations Modal** | -| `form_meta_edit` | Edit meta questions from **Layout & Settings** | - -## XLSForm configuration - -There are three sheets where locking profiles are defined and set: `survey`, -`settings` and `kobo--locking-profiles`. The sheet of `kobo--locking-profiles` -is not officially supported by [pyxform](https://github.com/XLSForm/pyxform) and -is KoboToolbox-specific. - -Form-level restrictions are defined in the `settings` sheet and question and -group-level restrictions are defined in the `survey` sheet. - -From within the `kobo--locking-profiles` sheet, all the locking profiles are -defined in a matrix structure, using the keyword "[locked](#locked)" to assign a -"[restriction](#restriction)" to a specific "[profile](#profile)". For example: - -**kobo--locking-profiles** - -Define the profiles and assign them restrictions. There is no limit on the -number of profiles that can be defined (`profile_1`, ..., `profile_n`) but there -are **only three** colours that differentiate their locking appearance in the -formbuilder. - -| restriction | profile_1 | profile_2 | profile_3 | -| :---------------- | :-------- | :-------- | :-------- | -| choice_add | locked | | | -| choice_delete | | locked | | -| choice_label_edit | locked | | | -| choice_order_edit | locked | locked | | -| form_appearance | | | locked | -| kobo--locking-profiles | +Form-level restrictions apply to the whole form. You can apply the following restrictions to your XLSForm: +| Name | Description | +|:------|:-------------| +| form_appearance | Prevents changes to the form [theme](https://support.kobotoolbox.org/form_style_xls.html). | +| form_replace | Prevents replacing the form in KoboToolbox using the **Replace Form** option. | +| group_add | Prevents creating new groups. | +| question_add | Prevents adding or cloning questions in a group. | +| question_order_edit | Prevents reordering questions. | +| language_edit | Prevents editing translations. | +| form_meta_edit | Prevents editing [metadata](https://support.kobotoolbox.org/metadata_xls.html) questions. | -

- Note that not all valid restrictions need to be included in the - restriction column, but an error will be thrown if an invalid - restriction is included. -

+### Locking an entire form -**settings sheet** +The `kobo--lock_all` setting can be added to the **settings** worksheet of your XLSForm. +- If set to **TRUE**, the entire form is locked and all granular restrictions become redundant. +- If set to **FALSE** (or omitted), only the restrictions defined in your locking profiles are applied. -Set form-level restrictions and `kobo--lock_all` boolean. +**settings worksheet** -| kobo--locking-profile | kobo--lock_all | -| :-------------------- | :------------- | -| profile_3 | false | -| settings | +| kobo--lock_all | +|:----------------- | +| TRUE | +| settings | -

- Note that omitting kobo--lock_all from the - settings sheet is equivalent to setting it to False. -

+## Configuring library locking in XLSForm -**survey sheet** +### Defining locking profiles -Set question and group-level restrictions. +Locking profiles are **sets of restrictions** that can be applied to questions, groups, or the whole form. They are defined in the **kobo--locking-profiles** worksheet of the XLSForm, and then applied in the **survey** and **settings** worksheets. You can create as many profiles as you need. -| type | name | label | kobo--locking-profile | -| :------------------- | :------ | :------------------ | :-------------------- | -| select_one countries | country | Select your country | profile_1 | -| select_one cities | city | Select your city | profile_2 | -| survey | +To define locking profiles in your XLSForm: +1. Create a new worksheet named **kobo--locking-profiles.** +2. Add a **restriction column**, which can include any restrictions from the tables above. +3. Create one column per **profile** (e.g., `profile_1`, `profile_2`). +4. In the cell corresponding to a **restriction** and a **profile**, include the keyword `locked` to assign a restriction to a profile. -**choices sheet** +**kobo--locking-profiles worksheet** -No restrictions can be set in the `choices` sheet. +| restriction | profile_1 | profile_2 | profile_3 | +|:-------------------|:----------|:----------|:----------| +| choice_add | locked | locked | | +| choice_delete | | locked | | +| choice_value_edit | locked | locked | | +| choice_label_edit | | locked | | +| choice_order_edit | | locked | | +| question_delete | locked | locked | | +| form_appearance | | | locked | -| list_name | name | label | -| :-------- | :-------- | :----------------------- | -| countries | canada | Canada | -| countries | usa | United States of America | -| cities | vancouver | Vancouver | -| cities | toronto | Toronto | -| cities | baltimore | Baltimore | -| cities | boston | Boston | -| choices | +### Applying profiles in the survey worksheet -This example XLSForm can be downloaded -here. +Once you have defined locking profiles in the **kobo--locking-profiles** worksheet, you can apply these profiles to specific questions and groups. To apply profiles in the `survey` worksheet: -### Import locked XLSForms +1. Create a column named **kobo--locking-profile** in the `survey` worksheet +2. For each question or group you want to restrict, define the locking profile in the `kobo--locking-profile` column. -Import your XLSForm as a `template` through the KoboToolbox UI by navigating to -your **Library** and clicking on **NEW** and then **Upload**. Ensure that you -select `template` from the **Choose desired type** drop-down menu and then -import your XLSForm. +**survey worksheet** -![choose template type](/images/library_locking/import-template.png) +| type | name | label | kobo--locking-profile | +|:-------------------------|:--------|:------------------|:--------------------| +| select_one country | country | Select your country | profile_1 | +| select_one city | city | Select your city | profile_2 | +| survey | -The locked template will now show in your library list view with a lock symbol. +### Applying profiles in the settings worksheet -![library list](/images/library_locking/library-list-view.png) +In addition to applying profiles to questions and groups in the `survey` worksheet, you can also apply a profile with form-level restrictions in the `settings` worksheet. -### Create project from locked template +To apply a profile to the `settings` worksheet: +1. Create a **kobo--locking-profile** column in the `settings` worksheet. +2. Specify the profile that you would like to apply. -Once a locked template has been added to your library -- either directly through -importing an XLSForm as a template, creating a template based on a locked survey -or adding a locked template from the public collections -- you can create a new -project. In the **Projects** section of the UI, click on **NEW** and then **Use -a template**. +**settings worksheet** -![create project from template](/images/library_locking/create-project-from-template.png) +| kobo--locking-profile | +|:---------------------| +| profile_3 | +| settings | -- Choose the locked template you want to use to create the new project. +

+Note: Restrictions cannot be applied in the choices worksheet. All choice-related restrictions are defined at the question or group level in the survey worksheet. +

-![select template](/images/library_locking/select-template-for-new-project.png) +## Using locked templates in KoboToolbox -- From there, continue to create the project. +Once you have created and uploaded a locked XLSForm as a template, you can use it to build new projects in KoboToolbox. -![create project](/images/library_locking/create-project.png) +### Importing a locked XLSForm into your Library -When this example locked template is used to create a new project, the -formbuilder will look like the following: +To import a locked XLSForm into your Library: +1. Go to your **Library** from the left menu bar in KoboToolbox. +2. Click **NEW**, then select **Upload**. +3. Upload your XLSForm file, and select **Upload as template.** -- The grayed out areas are those that have been disabled through the - restrictions. +![Upload template](images/library_locking/upload_template.png) -![overview](/images/library_locking/formbuilder.png) +The template will appear in your Library with a **lock symbol**, showing that it contains restrictions. -- A dialogue box above the first question will show an overview of some of the - form's restrictions. +### Creating a project from a locked template -![dialogue box](/images/library_locking/formbuilder-dialogue-box.png) +1. Go to the **Projects** home page. +2. Click **NEW**, then select **Use a template.** +3. Choose the locked template you want to use. +4. Continue creating your project as usual. -- Each question with locking profiles will display, in its settings, which - restrictions have been set. +![Use template](images/library_locking/use_template.png) -![question restrictions](/images/library_locking/formbuilder-question-settings.png) +When you open the project in the Formbuilder: +- A message will appear above the first question summarizing restrictions. +- Locked questions, groups, or form-level settings will appear **grayed out.** +- Each locked question shows which profile has been applied in its **Settings > Locked Features.** -- Some form-level settings will also be greyed out. +![Locked library](images/library_locking/locked.png) -![form-level restrictions](/images/library_locking/form-style.png) +## Troubleshooting -### Form validation +
+ Troubleshooting recommendations + If library locking does not work as expected, try the following: + +
-The following cases will currently throw a `FormPackLibraryLockingError`: +
+ +
+ Caveats and limitations + + +
-- If a locking profile name (column header in the `kobo--locking-profiles` - sheet) is "locked" (the same as the locking keyword) -- If a restriction listed in `kobo--locking-profiles` is invalid (not in the - list of [predefined restrictions](#restrictions)) -- If there is a sheet called `kobo--locking-profiles` but no `restriction` - column -- If no locking profiles are defined (column headers in the - `kobo--locking-profiles` sheet) -

- Validation of the XLSForm library locking features will be expanded in the - future. -

-### Caveats - -In some spreadsheet editors, two single dashes (`--`) are automatically -converted to an m-dash (—), therefore making it difficult to type `kobo--` into -a cell. We therefore convert all instances of n- and m-dashes into two single -dashes (when prefixed with `kobo`). An XLSForm with the sheet name of -"kobo—locking-profiles" will be converted to `kobo--locking-profiles` and -similarly for the column headers. - -## JSON representation - -There are two attributes of the asset where locking information can be accessed -and modified: `asset.summary` and `asset.content`. - -If `kobo--locking-profile` is a column name in the `survey` sheet, it will also -be listed in the `asset.summary.columns` array. - -In `asset.summary`, the following two Boolean attributes describe an overview of -the form's locking structure: - -- `lock_all`, and -- `lock_any` - -The logic by which each of those Booleans are set is as follows: - -- `lock_all` is `True` _only_ if `kobo--lock_all` is set to `True` in the - `settings` sheet, otherwise it's `False` -- `lock_any` is set to `True` if _any_ of the following cases are `True`: - - `lock_all` is `True`, - - A `kobo--locking-profile` is set in the `settings` sheet, or - - _At least one_ `kobo--locking-profile` is set in the `survey` sheet - -In the example above, the following will be present in the `asset.summary`: - -``` -{ - ..., - "columns": [ - ..., - "kobo--locking-profile" - ], - "lock_all": false, - "lock_any": true, - ... -} -``` - -In `asset.content`, an attribute of `content.kobo--locking-profiles` exists as -an array of JSON objects with the following structure: - -``` -[ - { - "name": "profile_1", - "restrictions": [ - "choice_add", - "choice_label_edit", - "choice_order_edit" - ] - }, - ... -] -``` - -In `content.settings`, the following will be present in a JSON object: - -``` -{ - "kobo--locking-profile": "profile_3", - "kobo--lock_all": false -} -``` - -And finally in `content.survey`, each question that has been assigned a locking -profile will have a `kobo--locking-profile` attribute as follows: - -``` -[ - { - "name": "country", - "type": "select_one", - ... - "kobo--locking-profile": "profile_1" - }, - { - "name": "city", - "type": "select_one", - ... - "kobo--locking-profile": "profile_2" - }, - ... -] -``` - -## Locking profiles and asset types - -Of the four asset types (`survey`, `template`, `question` and `block`), only -`template`s and `survey`s handle library locking features and the locks are -enforced _only_ on surveys. Practically, this means the following: - -Assume an XLSForm containing valid locking features is imported: - -- If imported as a `block`, then all traces of locking are excluded and/or - stripped from the asset. This results in a `block` asset that will be - equivalent to the same form uploaded without any locking features; -- If imported as a `survey` (imported through the **Projects** section) or - `template` then all locks are intact: - - If, from within the formbuilder: - - a question is added to the library, then all locks are stripped from - the new `question` asset - - a group of questions is added to the library as a `block`, then all - locks are stripped - - If a `template` is created _from_ the locked `survey` asset, then that - `template` will inherit all the locks the `survey` had (but since it is - a template, you are able to edit the contents in the formbuilder), - - If a `survey` is created _from_ a locked `template`, the survey will - inherit all the locks that the `template` had - -| Original Asset Type | Process/action | Resulting `asset`'s Status | -| :------------------ | :------------------------------------------------- | :------------------------- | -| `survey` | import XLSForm file of locked `survey` | locked | -| `survey` | create `template` from locked `survey` | locked | -| `survey` | create `question` from locked `survey`※ | not locked | -| `survey` | create `block` from locked `survey`※ | not locked | -| `template` | import XLSForm file of locked `template` | locked | -| `template` | create `survey` from locked `template` | locked | -| `template` | create `question` from locked `template`※ | not locked | -| `template` | create `block` from locked `template`※ | not locked | -| `block` | import XLSForm file of locked `block`※ | not locked | -| `block` | add locked `block` from Library into `survey` | not locked | -| `block` | add locked `block` from Library into `template` | not locked | -| `block` | create `question` from locked `block`※ | not locked | -| `question` | import XLSForm file of locked `block`※ | not locked | -| `question` | add locked `question` from Library into `survey` | not locked | -| `question` | add locked `question` from Library into `template` | not locked | -| `question` | create `block` from locked `question`※ | not locked | - -※ These actions are not possible in the UI. - -## Terminology - -### `kobo--lock_all` - -Attribute containing a Boolean value, set in the `settings` sheet and applies -all locking restrictions to the form and all questions and groups (rendering -granular locking profiles redundant). - -### `kobo--locking-profile` - -Column name in the `survey` and `settings` sheets where the locking profile is -assigned to a question or group (in `survey`) or to the form (in `settings`). - -### `kobo--locking-profiles` - -Sheet name where restrictions are assigned to profiles. - -### `locked` - -Keyword used to assign a restriction to a profile in the -`kobo--locking-profiles` sheet. - -### Profile - -The name assigned to a group of restrictions, defined in the -`kobo--locking-profiles` sheet. It is assigned to questions and groups in the -`survey` sheet and to the from in the `settings` sheet. - -### Restriction - -A granular locking attribute that can be assigned to a profile and control the -locking behaviour at the question, group or form level. - -### Unlocked - -A form containing no locking attributes. diff --git a/source/media.md b/source/media.md index ffce948d8..830e0d995 100644 --- a/source/media.md +++ b/source/media.md @@ -1,209 +1,190 @@ -# Adding Various Types of Media (image, audio, video) to a Form -**Last updated:** 15 Feb 2022 +# Adding media to an XLSForm +**Last updated:** Oct 26, 2025 -In addition to text questions and text choices, you can also add various types -of media (such as _image_, _audio_, and _video_) to your forms. Having media in -a form should sometimes be able to help you express your questions and choices -in a much better way. + -Media in a form works both on **Collect android app** and **Web forms -(Enketo)**. These are the media files that are currently supported: -| Media | Files | -| :---- | :------------------------------------------------------------ | -| Image | jpeg, png, svg | -| Audio | aac, aacp, flac, mp3, mp4, mpeg, ogg, wav, webm, x-m4a, x-wav | -| Video | 3gpp, avi, flv, mov, mp4, ogg, quicktime (qtff), webm, wmv | - -This support article aims to illustrate how forms with media can be created with -**KoboToolbox**. Follow the instructions outlined below to include media to your -survey project. - -## Step 1: Download Form as XLSForm - -Create a survey project in the formbuilder UI and then download your form as XLS -to add media settings to it. The formbuilder currently does not support adding -media to the form directly so you will need to edit the downloaded XLSForm to -complete this action. - - - -## Step 2: Add Media Columns to your XLSForm - -

The file names added to the XLSForm must match the file names you -gave to your image, audio, and -video files.

- -### Adding Image Media Columns: - -If you wish to add an **image** to a question, then type `media::image` as a -column header in the **survey** tab of your XLSForm. Type the image file name -along with an extension to the appropriate question just under the -`media::image` column header. - -Similarly, if you wish to add an **image** to a choice, then type -`media::image` as a column header in the **choices** tab of your XLSForm. Once -again type the image file name along with an extension to the appropriate choice -just under the `media::image` column header. - - - -### Adding Audio Media Columns: - -If you wish to add **audio** to a question, then type `media::audio` as a column -header in the **survey** tab of your XLSForm. Type the audio file name along -with an extension to the appropriate question just under the -`media::audio` column header. - -Similarly, if you wish to add **audio** to a choice, then type `media::audio` as -a column header in the **choices** tab of your XLSForm. Once again type the -audio file name along with an extension to the appropriate choice just under the -`media::audio` column header. - - - -### Adding Video Media Columns: - -If you wish to add video to a question, then type `media::video` as a column -header in the **survey** tab of your XLSForm. Type the video file name along -with an extension to the appropriate question just under the -`media::video` column header. - -Similarly, if you wish to add video to a choice, then type `media::video` as a -column header in the **choices** tab of your XLSForm. Once again type the video -file name along with an extension to the appropriate choice just under the -`media::video` column header. - - - -## Step 3: Handling Media Columns for Multiple Languages +KoboToolbox allows you to add media, including **images**, **audio files**, and **videos**, to notes, questions, and choices in your form. Adding media can increase user engagement and make forms more accessible for users with visual impairments or literacy barriers. -

This step is for those who have multiple languages in their survey -project.

+Form media works with both [KoboCollect](https://support.kobotoolbox.org/kobocollect_on_android_latest.html) and [Enketo web forms](https://support.kobotoolbox.org/enketo.html). The following types of media files are currently supported: -You may have a survey with multiple languages and want to add various types of -media relevant to specific languages. In such cases, you could follow the -illustrations provided below. - -### Handling Media Column for Image Media: - -If you wish to add image to a question, then type `media::image` as a column -header in the **survey** tab of your XLSForm. Type the image file name along -with an extension to the appropriate question just under the -`media::image::Language (language code)` column header. - -Similarly, if you wish to add image to a choice, then type -`media::image::Language (language code)` as a column header in the **choices** -tab of your XLSForm. Once again type the image file name along with an extension -to the appropriate choice just under the -`media::image::Language (language code)` column header. - - - -### Handling Media Column for Audio Media: - -If you wish to add audio to a question, then type -`media::audio::Language (language code)` as a column header in the **survey** -tab of your XLSForm. Type the audio file name along with an extension to the -appropriate question just under the -`media::audio::Language (language code)` column header. - -Similarly, if you wish to add audio to a choice, then type -`media::audio::Language (language code)` as a column header in the **choices** -tab of your XLSForm. Once again type the audio file name along with an extension -to the appropriate choice just under the -`media::audio::Language (language code)` column header. - - - -### Handling Media Column for Video Media: - -If you wish to add video to a question, then type -`media::video::Language (language code)` as a column header in the **survey** -tab of your XLSForm. Type the video file name along with an extension to the -appropriate question just under the -`media::video::Language (language code)` column header. - -Similarly, if you wish to add video to a choice, then type -`media::video::Language (language code)` as a column header in the **choices** -tab of your XLSForm. Once again type the video file name along with an extension -to the appropriate choice just under the -`media::video::Language (language code)` column header. - - - -## Step 4: Replace XLSForm - -Upload and replace your XLSForm into the existing project or create a new -project. - - - -## Step 5: Upload Media Files - -Go to **SETTINGS>Media**. Upload all media files that have been referenced in -your form. - - +| Media | Files | +| :--- | :--- | +| Image | jpeg, png, svg | +| Audio | aac, aacp, flac, mp3, mp4, mpeg, ogg, wav, webm, x-m4a, x-wav | +| Video | 3gpp, avi, flv, mov, mp4, ogg, quicktime (qtff), webm, wmv | -

Tip: Collect all media files that you will include in your survey -project. Provide a short file name for each of the media. File names -with a space (e.g., "red book") is not supported by the system. Hence, -you will need to either remove the space in between the names (e.g., -"redbook") or use '_' for a space (e.g., "red_book").

+This article covers the following topics: +- Adding media to survey questions +- Adding media to options choices +- Adding media to form translations +- Uploading media files to KoboToolbox -## Step 6: Deploy Form +

+ Note: The KoboToolbox Formbuilder does not currently support adding media files inside your forms. To add media, you will need to use XLSForm and then upload your XLSForm to KoboToolbox. To learn more about downloading and editing your form as XLSForm, see Using XLSForm with KoboToolbox. +

+For hands-on practice with adding media attachments in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

-Once you have replaced the XLSForm and then uploaded all the media files, you -will need to deploy your survey. +## Adding media to questions in XLSForm + +To add media files to questions or notes in your XLSForm: +1. Add a new question in the `survey` worksheet, specifying the **type**, **name**, and **label** (optional). + - Use a **note** question type if you want to display the media file without collecting any data (e.g., an organization logo or introduction video). + - Adding a label is optional when including a media file. +2. Add a column for the media you want to include. Name it `image`, `video`, or `audio`, depending on the media type. +3. In the media column, in the row of the question you have added, enter the exact name of the media file **including the extension**. + - For example: `logo.png` or `intro.mp4`. + +**survey worksheet** + +| type | name | label | image | +| :--- | :--- | :--- | :--- | +| text | Q1 | In your own words, how would you describe the image above? | q1.png | +| survey | - +

+ Note: Previously, the format media::file_type was used for media column names (e.g., media::image, media::video, media::audio). The simplified format using only the media type without the media:: prefix is now more commonly adopted (e.g., image, video, audio). +

+ +### Uploading media files to KoboToolbox + +To upload the media files to KoboToolbox: +1. Go to your [KoboToolbox account](https://www.kobotoolbox.org/sign-up/). +2. In your KoboToolbox project, navigate to **SETTINGS > Media**. +3. Upload the media files that you have added to your XLSForm, ensuring the file name is exactly the same. +4. Deploy or redeploy your form to see media changes. + +![Upload media files](images/media/upload_media.png) + +## Adding media to choices in XLSForm + +To add media files to option choices in your XLSForm: +1. Add a [select type question](https://support.kobotoolbox.org/question_types_xls.html#select-question-types) in the `survey` worksheet. +2. In the `choices` worksheet, add a **list_name**, **name**, and **label** (optional) for your choices. + - Adding a label is optional when including a media file. If you wish to use the media files as options label, omit the label text. +3. Add a column for the media you want to include. Name it `image`, `video`, or `audio`, depending on the media type. +4. In the media column, in the row of the choices you have added, enter the name of the media file **including the extension**. + - For example: `goat.png` or `fish.png` + +**survey worksheet** + +| name | type | label | +| :--- | :--- | :--- | +| select_one animals | animals | Which of these is your favorite animal? | +| survey | + +**choices worksheet** + +| list_name | name | label | image | +| :--- | :--- | :--- | :--- | +| animals | goats | Goats | goat.png | +| animals | cows | Cows | cow.png | +| animals | chicken | Chickens | chicken.png | +| animals | pigs | Pigs | pig.png | +| animals | fish | Fish | fish.png | +| choices | + +### Uploading media files to KoboToolbox + +To upload the media files to KoboToolbox: +1. Go to your [KoboToolbox account](https://www.kobotoolbox.org/sign-up/). +2. In your KoboToolbox project, navigate to **SETTINGS > Media**. +3. Upload the media files that you have added to your XLSForm, ensuring the file name is exactly the same. +4. Deploy or redeploy your form to see media changes. + +## Adding media to translations + +In XLSForms that are [translated in multiple languages](https://support.kobotoolbox.org/language_xls.html), you can include different media files for each language by adding new **image**, **audio**, or **video** columns. + +To add media files for different languages in your survey worksheet: + +1. Rename your media columns using the format **media_type::language (code)**, where `media_type` is the type of media file and `language` is the default language. + - For example: `image::English (en)` +2. Add a new media column for each translation language using the format **media_type::language (code)**. + - For example: `audio::Spanish (es)` +3. In the media column for each language, enter the name of the media file you wish to include, including the extension. + - To use the same media file for each language, enter the same file name as the one in the default language column. + +

+ Note: If a media file is not listed in a translation column, it will not be displayed for that language. +

+ +**survey worksheet** + +| type | name | label | video::English (en) | video::Chichewa (ny) | +| :--- | :--- | :--- | :--- | :--- | +| note | intro | Before you answer the form, watch the video below: | intro.mp4 | intro_ny.mp4 | +| survey | + +### Uploading media files to KoboToolbox -

Each time new media files are added or changed, you need to -redeploy your project for the change to take effect. -You can see your new media when previewing your form -before redeployment.

+To upload the translated media files to KoboToolbox: +1. Go to your [KoboToolbox account](https://www.kobotoolbox.org/sign-up/). +2. In your KoboToolbox project, navigate to **SETTINGS > Media**. +3. Upload the media files that you have added to your XLSForm, ensuring the file name is exactly the same. +4. Deploy or redeploy your form to see media changes. -## Step 7: Collect Data +

+ Note: To learn more about managing translations in XLSForm, see Adding translations in XLSForm. +

+ +## Troubleshooting -You can now go back to **Form>Collect Data**, and then click **Open** to check -if the media are properly displayed. +
+Error when deploying or viewing form +If you face an error when deploying or viewing your form, check the following: + +
- +
-

Animated GIF files are currently not supported by Enketo or -Collect android app. Aligning media to a desired form location (left -alignment, center alignment or the right alignment) is also not -possible.

+
+Media files not appearing in deployed form +If media files are not appearing in your deployed form, check the following: + +
-## Tips & Tricks +
-### Identifying the filename, extension, and size of a media file on Windows +
+Changing the size of a media file +To control the size of images displayed in your questions or choices, you must upload media files with the desired dimensions. Note that using very large files can increase loading times in Enketo forms. +
+ +
-- Select a media file (image, audio, or video). -- Right click your mouse when the media file is still being selected. +
+Form takes a long time to load +Enketo forms will load slowly if your media files are large. Reduce the size of image, video, or audio files before uploading them to the server to improve loading times. +
-![Dropdown select properties](images/media/dropdown_select_properties.png) +
-- Then select **Properties**. -- You should now be able to see the *filename* and *extension* of the media - file under the **General** tab. +
+Changing alignment of media files +Media in KoboToolbox forms is center-aligned by default, and custom alignment (left or right) is not possible. +
-![Image properties](images/media/image_properties.png) +
-- You should also be able to identify the media dimensions and size under the - **Details** tab. If you wish to have small images in your question or - choices, you will need to upload media with a smaller dimension, or - vice-versa. +
+Animated GIF files not supported +Animated GIF files are not currently supported by either Enketo web forms or the KoboCollect Android app. +
-

The media in an Enketo form will take more time to load if you -have large files. Try reducing the image, video or audio file sizes -before uploading them to the server.

+
-![Image details](images/media/image_details.png) +
+Unable to upload media file +The maximum size for media uploads is 100 MB. Files exceeding this limit must be reduced in size before uploading. +
-

You can access the XLSForm here and the media files here that were used -in this article.

diff --git a/source/metadata_xls.md b/source/metadata_xls.md new file mode 100644 index 000000000..d7ff17d0a --- /dev/null +++ b/source/metadata_xls.md @@ -0,0 +1,53 @@ +# Form metadata in XLSForm + +Metadata questions automatically gather information about the data collection process, such as the date, time, and device used, without requiring input from the respondent. + +Metadata questions are not visible to respondents. The information collected in the background can be used for auditing, to ensure data integrity, and to support data analysis. + +

+Note: This article focuses on adding metadata questions in XLSForm. To learn about adding metadata questions in the KoboToolbox Formbuilder, see Form settings and metadata. +

+ +## Adding metadata questions in XLSForm + +Metadata questions are added to XLSForm in the same way as any other question types: + +1. Enter the metadata question **type** in a new row, using the exact name shown [in the table below](https://support.kobotoolbox.org/metadata_xls.html#available-metadata-questions-in-xlsform). +2. Include a question **name**. +3. Question **labels** are not required, as they are not displayed in the form. + +**survey worksheet** + +| type | name | label | +|:-----|:-----------|:-------------| +| start | start_time | | +| end | end_time | | +| survey | + +## Available metadata questions in XLSForm + +Available metadata questions in XLSForm include: + +| Type | Description | +|:--------------------|:-------------| +| `start` | Records the exact time and date when a submission is started. | +| `end` | Records the date and time when a submission is finalized. | +| `today` | Records the date of the submission. | +| `deviceid` | Records the unique identification of the device or browser used to collect data. The deviceid is automatically generated and cannot be modified by users.

**Note:** In KoboCollect, the deviceid is updated whenever the app is reinstalled on a device. In Enketo, the deviceid resets any time a new browser window is used. | +| `username` | In KoboCollect, records the username saved in the KoboCollect app settings. If no username is set, it records the one used to sign in to the server.
In Enketo, records the account username only if authentication is required.

**Note:** Because the `username` field can be edited in KoboCollect, it may not match the account used to authenticate to the server. To see which account submitted the data, refer to the automatically generated `_submitted_by` field.| +| `phonenumber` | Records the phone number stored in the KoboCollect app settings. This metadata question is not supported in Enketo. | +| `email` | Records the email address from the KoboCollect app settings. This metadata question is not supported in Enketo. | +| `start-geopoint` | Captures GPS coordinates when the form is first opened. Can be used to warm up the device GPS so that later GPS questions can reach accurate readings more quickly. | +| `background-geopoint` | Captures GPS coordinates when a specific question is answered. The question must be specified in the trigger column of the background-geopoint question. | +| `background-audio` | Records audio in the background while a form is open. To learn more about this feature, see Recording interviews with background audio recording. | +| `audit` | Captures a detailed log of the interview process, including start time, end time, location, and user actions during the entire data collection process. This metadata question is not supported in Enketo.

To learn more about using the audit question for audit logs and configuring settings, see Form Audit Log (ODK). | + +## Configuring metadata in KoboCollect + +The user’s default email, phone number, and username can be [configured](https://support.kobotoolbox.org/kobocollect_settings.html#user-and-device-identity-settings) and modified in the KoboCollect app: +1. Open the KoboCollect app. +2. Tap the **Project icon** in the top right corner of your screen. +3. Tap **Settings**. +4. Scroll down to **User and device identity**, then **Form metadata**. +5. Enter the username, phone number, and/or email address. You can also view the current device ID. + diff --git a/source/option_choices_xls.md b/source/option_choices_xls.md new file mode 100644 index 000000000..9e94f9b77 --- /dev/null +++ b/source/option_choices_xls.md @@ -0,0 +1,103 @@ +# Managing option choices in XLSForm +**Last updated:** Oct 10, 2025 + +XLSForm simplifies the creation and management of **option choice lists** for survey forms. This is particularly useful for long or repetitive lists, such as country or city names. Option choices are defined for `select_one`, `select_multiple`, or `rank` [questions](https://support.kobotoolbox.org/question_types_xls.html). + +This article details how to define and manage option choices in XLSForm for complex forms, including best practices for defining choice names. + +

+To learn more about building forms in XLSForm, see Getting started with XLSForm. +

+ +## Defining option choices in XLSForm +Option choices are defined in the `choices` worksheet of your XLSForm. The `choices` worksheet includes three mandatory columns: + +| Column | Description | +| :--------- | :-------- | +| `list_name` | Unique identifier for a list of option choices, which links the question in the `survey` worksheet to its choice list in the `choices` worksheet. | +| `name` | Short, unique name used to refer to each option choice. | +| `label` | Choice text as it will be displayed in the form. | + +To define a list of option choices in XLSForm: + +1. In the `choices` worksheet, enter the **name of the list of choices** in the `list_name` column. +2. Enter a short `name` and a `label` for each option, using the same `list_name` for all options in the list. + +**choices worksheet** + +| list_name | name | label | +| :--------- | :--------- | :--------- | +| marital_options | single | Single | +| marital_options | married | Married | +| marital_options | separated_divorced | Separated/Divorced | +| marital_options | widowed | Widowed | +| choices | + +3. In the `survey` worksheet, add your survey question. In the `type` column, enter the question type followed by a single space and then the `list_name` for your list of choices. + - A list of choices can be reused across multiple questions in the `survey` worksheet. + +**survey worksheet** + +| type | name | label | +| :--------- | :--------- | :--------- | +| acknowledge | consent | Do you agree to proceed with the interview? | +| select_one marital_options | marital_status | What is your marital status? | +| survey | + + +## Best practices for defining choice names + +When data is downloaded in [XML values and headers format](https://support.kobotoolbox.org/export_download.html#value-and-header-format), each question appears as its own variable or column in the dataset. The values inside each column are the **choice names** defined in your `choices` worksheet, rather than the full labels shown to respondents. This format is recommended for analysis, since it provides short, consistent variable names and coded values that are easier to work with than full question or option labels. + +When defining choice names: +- Use only **letters, numbers, and underscores**. Spaces and special characters are not allowed. +- Avoid very long or complex strings of text, as these values will appear in your exported dataset and may be used in [form logic](https://support.kobotoolbox.org/form_logic_xls.html). +- Keep names **consistent** across lists to facilitate data analysis. + + +## Managing choice lists in XLSForm + +### Reusing choice lists +Using **`list_name`** in XLSForm allows you to easily **reuse choice lists** across multiple questions, eliminating the need for manual re-entry. For example, you can create a `yes_no` choice list and apply it to all your Yes/No questions. This helps build forms more efficiently and consistently. + +### Translating choice lists + +XLSForm simplifies the translation of choice lists. You can add multiple labels for different languages, with each translation in a separate **`label`** column. The underlying choice names remain the same, which ensures the exported dataset is consistent across translations and facilitates analysis. + +

+To learn more about adding translations in XLSForm, see Adding translations in XLSForm. +

+ +### Media files as option choices + +In addition to text, option choices in XLSForm can also be **media files**, such as images, audio, or video. This enhances the survey experience by providing visual or auditory cues to respondents. + +

+To learn more about using media files as option choices, see Adding media to an XLSForm. +

+ +### Filtering choice lists + +XLSForm allows you to filter option choice lists based on responses to previous questions. This feature, known as **choice filters**, can be used in various ways. For example, they can be used for **cascading select questions**, where the choice list for a child question (e.g., cities) is filtered based on the response to a parent question (e.g., country). They can also be used for filtering a multiple choice question to display only options selected in a previous question. + +

+To learn more about filtering choice lists in XLSForm, see Adding choice filters in XLSForm. +

+ +### Duplicating choice names + +Within a given list of option choices, **choice names must be unique**. However, the same choice name can be reused across different lists. For instance, a `yes_no` choice list and a `yes_no_maybe` choice list can both include `yes` and `no` choice names. + +By default, deploying a form with repeated choice names in the same list will result in an error. However, when using choice filters, you may need to allow duplicate choice names within a list. To enable this, activate the `allow_choice_duplicates` setting in your `settings` worksheet. + +

+For more information, see Form settings in XLSForm. +

+ +### Managing long choice lists + +For very large choice lists, containing hundreds or thousands of options, it is recommended to use `select_one_from_file` or `select_multiple_from_file` question types, which link a survey question to an **external file** containing the list of choices. This approach is more efficient than manually entering choices inside the XLSForm, helps avoid slow loading times and large XLSForms, and simplifies managing or editing extensive option sets. + +

+To learn more about external choice lists in XLSForm, see Selecting options from an external file. +

diff --git a/source/pull_data_kobotoolbox.md b/source/pull_data_kobotoolbox.md index d3e40807f..a92c359cf 100644 --- a/source/pull_data_kobotoolbox.md +++ b/source/pull_data_kobotoolbox.md @@ -1,38 +1,110 @@ -# Pull Data Functionality in KoboToolbox +# Pulling data from an external CSV **Last updated:** 18 Aug 2025 +The `pulldata()` function in XLSForm lets you dynamically retrieve information from an external CSV file while completing a form. This allows you to reference existing datasets and automatically pull in related details, avoiding the need for enumerators to re-enter the same information. + +For example, you can use `pulldata()` to: +- **Auto-fill related information:** When an ID, code, or key is entered, automatically retrieve linked details such as a name, category, or description. +- **Preload background data:** Load information from external files so enumerators only need to collect new or updated data. + +Using `pulldata()` helps reduce errors, saves time during data collection, and ensures that forms remain consistent with external reference datasets. This function is supported in both the KoboCollect Android app and Enketo web forms. We recommend using XLSForm to set up the `pulldata()` function. + +This article covers the following steps for pulling data from an external CSV: +- Setting up your external CSV +- Setting up your XLSForm +- Uploading your external CSV to KoboToolbox + +## Setting up your external CSV + +To use `pulldata()`, first prepare an external CSV file containing the reference data you want to retrieve. Each row should represent a unique record (for example, a participant, location, or item) and the file should include at least two columns. One column must contain the **index variable** that matches the values entered in your form. + +The **index variable** acts as the [primary key](https://en.wikipedia.org/wiki/Primary_key) that links your XLSForm to the external CSV. It should be a unique identifier that exists in both files, such as a participant ID, a district name, or another matching code. + +The remaining columns can include any additional details you want to retrieve, such as names, categories, or descriptions. Ensure the CSV file is clean, consistently formatted, and saved with the `.csv` extension. + +## Setting up your XLSForm + +Once you have set up your external CSV, configure your XLSForm in the following way: + +1. Ensure your XLSForm includes a question that serves as the **index variable**. +2. Add a `calculate` field to your survey. Give the field a `name`. +3. In the `calculation` column, use the **pulldata()** function to specify which field in the CSV to pull from. Use the following syntax: `pulldata('csv','pull_from', 'csv_index', '${survey_index}')`. + - `csv` is the name of the CSV file, without the extension. + - `pull_from` refers to the column in your CSV file that contains the data you want to import into your form. + - `csv_index` is the column in your CSV file that contains the **index variable.** + - `survey_index` is the name of the question in your survey that contains the **index variable.** + + **survey worksheet** + + | type | name | label | calculation | +|:-----------|:------------------|:-------------------------------------------|:-------------| +| text | respondent_id | Respondent ID | | +| calculate | eligibility_status | | pulldata('eligibility', 'status', 'ID', 'respondent_id') | +| note | eligibility_not | Respondent is ${eligibility_status} for the study. | | +| survey | + +In the example above, the calculation retrieves the value from the `status` column of the `eligibility.csv` file, in the row where the `ID` in the CSV matches the ID entered in the `respondent_id` question of your form. + +

+Note: After using the pulldata() function to retrieve external CSV data, you can reference that field in subsequent skip logic conditions, constraints, and labels, just like any other field or calculation. +

+ +## Uploading your external CSV to KoboToolbox + +The final step in linking your external CSV file to your form is uploading the file to KoboToolbox. To do this: +1. Navigate to your project **SETTINGS**, and open the **Media** tab. +2. Upload the CSV file(s) with the exact name you have used in your XLSForm. +3. Deploy or redeploy the form. + +![Upload media](images/pull_data_kobotoolbox/upload_media.png) + +## Troubleshooting + +
+ Non-English fonts or special characters are not displaying correctly + Save your CSV file in UTF-8 format. This ensures that Android devices can render non-English text or special characters properly. +
+ +
+ +
+ Numeric values are not working as expected + All data pulled from a CSV file is treated as text. To use these values as numbers, apply the int() or number() functions to the retrieved value in your XLSForm. +
+ +
+ +
+ Protecting sensitive data + If your CSV contains sensitive information that you do not want uploaded to the server, upload a blank CSV file with your form. Then manually replace it on each device with the real CSV file. This approach only works with the KoboCollect app. +
+ +
+ +
+ Slow form loading with large files + If you are using very large CSV files, you may experience slow form loading in KoboCollect. To resolve this, we recommend using the trigger column to pull data from the external file once, rather than recurrently in the background. +
+ +
+ +
+ Pulling dates from external CSV files + If you are storing dates in an external CSV file and want to pull them into a form, ensure they are in the format YYYY-MM-DD. If you are editing your CSV in Excel, add a single quote ' in front of the date to avoid automatic date formatting in Excel. +
+ +
+ +
+ Pull data not working properly + If the pulldata() functionality is not working properly, try the following: + +
+ +
-This is best done on xls version of the form. - -- In the survey side of the form add a calculate field to your survey. -- Give that field a name that you want -- Then in its calculation column, call the pulldata() function, indicating - which field to pull from which row of which .csv file. This can be achieved - by writing as follows - `pulldata(‘nameofcsv’, ‘columnheadingtopulldatafrom’, ‘columncheckformatchingTEXT’, ‘TEXTtoCheckfor’` - - ![image](/images/pull_data_kobotoolbox/xls.png) - -- Note your CSV needs to have at-least two columns and ensure that the - columntocheckformatchingTEXT is always the first column from the left -- TexttoCheckfor can also be referenced from an earlier field question by - using `${Question}` as an example above -- Once you have finished updating the xls you will need to upload your form - from xls (do not edit it on the formbuilder), you will then upload your CSV - the same way you would upload your images. -- When you deploy your file the csv will be downloaded to the media files - -**Things to note** - -- This will work both on KoboCollect app and Enketo (web form). -- Compress a large .csv file into a .zip archive before uploading it. -- Save .csv file in UTF-8 format if pre-loaded data contains non-English fonts - or special characters this enables your Android device to render the text - correctly. -- Data fields pulled from a .csv file are considered to be text strings - therefore use the int() or number() functions to convert a pre-loaded field - into numeric form. -- If the .csv file contains sensitive data that you may not want to upload to - the server, upload a blank .csv file as part of your form, then replace it - with the real .csv file by hand-copying the file onto each of your devices. -- If you are facing error messages when using this feature, try changing the file name to remove any underscores or symbols. diff --git a/source/question_options_xls.md b/source/question_options_xls.md new file mode 100644 index 000000000..58c69ecda --- /dev/null +++ b/source/question_options_xls.md @@ -0,0 +1,192 @@ +# Using question options in XLSForm + +When designing a form in XLSForm, you can customize questions by adding hints, setting appearances, making a question mandatory, and more. To do this, you can add new columns in the **survey worksheet** of your XLSForm. These columns can be added anywhere in the worksheet, as long as the column name is typed exactly as required. + +This article covers the most common question options and how to add them to your XLSForm, including question hints, required questions, default responses, and question parameters. + +

+ Note: This article focuses on defining question options in XLSForm. To learn about question options in the KoboToolbox Formbuilder, see Using the question options. +

+For hands-on practice with question options in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Question hints + +**Question hints** allow you to add instructions or additional information to your form. There are two types of hints that you can add in XLSForm: +- **Regular hints** are used to provide additional information for respondents or enumerators directly in the form. They are always visible and displayed below the question label. +- **Guidance hints** are used to provide additional information during form development, enumerator training, or data collection. They are not displayed by default. + +### Adding question hints in XLSForm + +To add a **regular hint** in XLSForm: +1. Add a **hint** column to the `survey` worksheet. +2. In the same row as your question, enter the text that should be displayed as a hint for that question. + +To add a **guidance hint** in XLSForm: +1. Add a **guidance_hint** column to the `survey` worksheet. +2. In the same row as your question, enter the text that should be included as additional guidance. + +**survey worksheet** + +| type | name | label | hint | guidance_hint | +| :--- | :--- | :--- | :--- | :--- | +| integer | height | What is your height? | In centimeters | If the respondent does not know their height, enter 0 | +| survey | + +

+Note: Question hints can also be translated into multiple languages. For more information on translating forms, see Adding translations in XLSForm. +

+ +### Displaying guidance hints in KoboCollect + +In Enketo web forms, guidance hints appear in a collapsible **More Details** section. In KoboCollect, they are hidden by default, but you can [change your project settings](https://support.kobotoolbox.org/kobocollect_settings.html#form-management-settings) to always display them or show them in a collapsible section. + +To display guidance hints in KoboCollect, follow the steps below: +1. Tap the **Project icon** in the top right corner of your screen. +2. Tap **Settings**. +3. Under **Form management**, select **Show guidance for questions**. +4. Choose a display option: **No**, **Yes - always shown**, or **Yes - collapsed**. + +

+Note: Guidance hints are always displayed in printed forms. +

+ +## Required questions + +By default, questions in a form are optional. Setting a question as **required** makes it mandatory for the respondent to answer. This can be useful for ensuring submissions are complete and avoiding missing data. + +

+Note: Skip logic conditions take precedence over required settings, meaning that if a required question is hidden by skip logic, it is no longer mandatory to answer. +

+ +To set a question as required in XLSForm: +1. Add a `required` column to the `survey` worksheet. +2. In the `required` column, enter any of the following: **TRUE**, **true**, or **yes**. +3. For optional questions, leave the `required` column blank or enter any of the following: **FALSE**, **false**, or **no**. + +If a respondent does not answer a required question, they will not be able to proceed to the next page or submit the form. The default required message "This field is required" will be displayed. + +

+Note: Only questions that require an input should be marked as required in your XLSForm. If note questions are marked as required, you will not be able to continue or submit the form. +

+ +### Changing the default required message + +You can change the default required message in your XLSForm by following the steps below: + +1. Add a **required_message** column to the `survey` worksheet. +2. Enter the text you wish to display when users leave a required question blank. + +**survey worksheet** + +| type | name | label | required | required_message | +| :--- | :--- | :--- | :--- | :--- | +| select_one education | education_level | What is the highest level of education you have completed? | TRUE | | +| integer | age | What is your age? | TRUE | Please respond to this question before continuing. | +| survey | + +

+Note: Custom form logic can be used to make a question required or optional based on a previous response. To learn more about condition-based required logic, see Adding required logic in XLSForm. +

+ +## Default responses + +A **default response** populates a question with a predefined answer based on a common or expected response. The default response can be fixed or [dynamically determined](https://support.kobotoolbox.org/question_options_xls.html#setting-dynamic-default-responses) based on the response to a previous question. + +The default response will be recorded as the final answer when the form is submitted **unless modified by the respondent** during data collection. To prevent respondents from editing a default response, add a **read-only** column and set it to **TRUE**. + +

+Note: Although default responses can make data collection more efficient by prepopulating the form with expected or common responses, they also risk introducing bias or errors in the data, and should be used with caution. +

+ +To set a fixed default response in XLSForm: +1. Add a **default** column to the `survey` worksheet. +2. Enter the default response, following the [appropriate format](https://support.kobotoolbox.org/question_options_xls.html#default-response-format) for the question type. + +**survey worksheet** + +| type | name | label | default | +| :--- | :--- | :--- | :--- | +| text | name | What is your name? | John Doe | +| integer | age | What is your age? | 50 | +| select_one marital_options | marital_status | What is your marital status? | married | +| select_multiple income_options | income_sources | What are your sources of income? | formal_work farm_business | +| date | dob | When were you born? | 1990-03-25 | +| date | interview_date | When was this interview conducted? | today() | +| survey | + +### Default response format + +The format of the default response depends on the question type and the data being collected: + +| Question type | Default response format | +| :--- | :--- | +| integer | Number | +| text | Text (without quotation marks) | +| select_one | Choice **name** (as defined in the choices worksheet) | +| select_multiple | Choice **name(s)**, separated by a **space** if there are multiple | +| date | Date in the YYYY-MM-DD format. If needed, prefix the date with a single quote (') in Excel to avoid potential formatting issues. | + +### Setting dynamic default responses + +Default responses entered in the `default` field must be fixed values. To set a **dynamic default response** based on a previous answer, use the **calculation** and **trigger** columns instead of the `default` column: +1. In the `calculation` column, enter the **reference to the question** that will dynamically populate the default response. +2. In the `trigger` column, enter the question that will activate the calculation. + - Typically, this would be the same question referenced in the `calculation` column, so that any change to the trigger question will also update the default response. + +**survey worksheet** + +| type | name | label | calculation | trigger | +| :--- | :--- | :--- | :--- | :--- | +| text | hh_name | Name of the head of household | | | +| text | phone | Household phone number | | | +| text | phone_name | Name of the phone owner | ${hh_name} | ${hh_name} | +| survey | + + +## Question parameters + +Question parameters in XLSForm allow you to fine-tune how your questions behave beyond basic settings. + +To add question parameters in XLSForm: +1. Add a **parameters** column to the `survey` worksheet. +2. Enter the appropriate [parameter](https://support.kobotoolbox.org/question_options_xls.html#common-question-parameters) for your question type. +3. Some parameters can be combined and applied to the same question. Combine parameters by entering them in the same cell and separating them with a space. + +**survey worksheet** + +| type | name | label | parameters | +| :--- | :--- | :--- | :--- | +| select_one reasons | reasons | Please select all reasons that apply. | randomize=true | +| range | phone | Please select a number between 1 and 5. | start=1 end=5 step=1 | +| survey | + +### Common question parameters + +Different question types in `XLSForm` have different parameters. The most common parameters are: + +| Parameter | Question type | Description | +| :--- | :--- | :--- | +| randomize=true | rank, select_one, select_multiple | Randomizes the order of option choices | +| start=1 end=5 step=1 | range | Defines the minimum value, maximum value, and interval between numbers | +| capture-accuracy=20 | geopoint | Specifies the minimum acceptable GPS accuracy (in meters) for automatically capturing a location | +| warning-accuracy=50 | geopoint | Triggers a warning message if the GPS accuracy is not within the specified accuracy threshold | +| max-pixels=480 | image | Limits the maximum pixels for a photo, to reduce the image file size and improve upload speed | +| quality=low | audio | Captures a lower quality audio recording | +| quality=voice-only | audio | Captures the lowest quality audio recording | + +## Additional question options + +XLSForms can include additional columns in the survey worksheet for more advanced forms and functionalities. A few are listed below. + +| XLSForm column | Description | +| :--- | :--- | +| read_only | If `yes` is entered in the `read_only` field, the question cannot be edited by the respondent. `read_only` fields can be combined with `default` or `calculation` fields to display information to the respondent. | +| trigger | The trigger column can be used to run a calculation only when the response to another visible question in the form is changed. For more information, see XLSForm documentation. | +| body::accept | To limit the accepted file types for `file` questions, specify file extensions in the `body::accept` column, separated by a comma (e.g., .pdf, .doc). | + +Other columns can also be added to incorporate form logic into your XLSForm. + +

+ To learn more about adding form logic, see Adding skip logic in XLSForm, Adding constraints in XLSForm, Adding required logic in XLSForm, Adding choice filters in XLSForm, and Adding calculations in XLSForm. +

diff --git a/source/question_types_xls.md b/source/question_types_xls.md new file mode 100644 index 000000000..bed97b9f3 --- /dev/null +++ b/source/question_types_xls.md @@ -0,0 +1,128 @@ +# Question types in XLSForm +**Last updated:** Oct 10, 2025 + +When adding questions to an XLSForm, you'll need to choose the appropriate **question type**. The question type will depend on the kind of information you want to collect: some question types are more suited for text, others for numbers, dates, or multiple choice inputs. + +The question type in XLSForm is entered in the **type** column of the **survey** worksheet. Always use the exact spelling and letter case. You can add additional [appearances](https://support.kobotoolbox.org/appearances_xls.html) to most question types to modify their display or functionality. + +

+Note: While XLSForm is fully integrated within KoboToolbox, some question types have different names and functionalities in the Formbuilder than they do in XLSForm. +

+ +This article covers available question types in XLSForm, including their descriptions and Formbuilder equivalents. Links are provided at the end of each section for more information on question type functionalities and appearances during data collection. + +

+To learn more about building forms in XLSForm, see Getting started with XLSForm. +

+ +### Select question types + +Select questions allow respondents to choose from predefined options. For `select_one`, `select_multiple`, and `rank` questions, [option choices](https://support.kobotoolbox.org/option_choices_xls.html) are defined in the **choices** worksheet of the XLSForm. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `select_one` | Allows respondents to select one option from a predefined list. | Select One | +| `select_multiple` | Allows respondents to select multiple options from a predefined list. | Select Many | +| `rank` | Allows respondents to rank items or options in a choice list. | Ranking | +| `acknowledge` | A single checkbox that respondents can select to acknowledge their agreement with a statement. | Acknowledge | +| `select_one_from_file` | Allows respondents to select one option from a predefined list, stored in an external CSV file. | Select One From External File | +| `select_multiple_from_file` | Allows respondents to select multiple options from a predefined list, stored in an external CSV file. | Select Many From External File | + + +

+To learn more about select question types in KoboToolbox, see Select One and Select Many question types, Rating vs Ranking question types, Acknowledge question type, and Select One or Many From External File question types. +

+ + +### Numeric question types + +Numeric questions are used to collect whole numbers, decimal numbers, or values within a specified range. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `integer` | Allows respondents to input whole numbers. | Number | +| `decimal` | Allows respondents to input numbers that may contain decimal points. | Decimal | +| `range` | Allows respondents to select a numeric value within a specified range constrained by minimum and maximum values, configured in the **parameters column**. | Range | + + +

+To learn more about numeric question types in KoboToolbox, see Number, Decimal, and Range question types. +

+ + +### Text and note question types + +Text questions are used to collect open-ended responses, while note questions provide information or give instructions to respondents. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `text` | Provides a text box to collect open-ended responses when choices cannot be easily predefined, such as names, opinions, or detailed descriptions. | Text | +| `note` | Provides information to the respondent without requiring any input, such as instructions or explanations. | Note | + + +

+To learn more about text and note question types in KoboToolbox, see Text and Note question types. +

+ +### Media question types + +Media questions allow respondents to upload or record images, audio, and video files, or to scan barcodes directly into their forms. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `image` | Allows respondents to upload images or take photos when using the KoboCollect app. The quality of image files can be adjusted in the **parameters** column. | Photo | +| `audio` | Allows respondents to upload an audio file or record audio as a response to a specific question. The quality of audio files can be adjusted in the **parameters** column. | Audio | +| `video` | Allows respondents to upload videos or record videos when using the KoboCollect app. | Video | +| `file` | Allows respondents to upload files, such as text files, spreadsheets, and PDF files. Accepted file types can be restricted by specifying file extensions in the **body::accept** column (e.g., `.pdf, .docx`). | File | +| `barcode` | Scans a QR code to collect embedded information using the device's camera in KoboCollect. | Barcode | +| `background-audio` | Collects audio continuously while the form is open. Audio recording begins when the form is opened and continues until the form is closed. | Background Audio Recording | + + +

+To learn more about media question types in KoboToolbox, see Media question types, Barcode/QR code question type, and Recording interviews using background audio recording. +

+ +### GPS question types + +GPS questions are used to capture the geographic coordinates of a location, path, or area directly within your forms. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `geopoint` | Collects a single geographic location, such as the coordinates of a specific school, clinic, or house. Default accuracy and warning accuracy can be configured in the **parameters** column. | Point | +| `geotrace` | Records multiple GPS points that form a line, for example to track a path, trace a route, or map a drain. | Line | +| `geoshape` | Collects points that form an enclosed area, such as a plot of land or a field. | Area | + + +

+To learn more about GPS question types in KoboToolbox, see GPS question types. +

+ +### Date and time question types + +Date and time questions are used to capture specific calendar dates, times, or both in a single response. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `date` | Captures a specific calendar date, typically in the format of day, month, and year. | Date | +| `time` | Captures a specific time in hours and minutes. | Time | +| `datetime` | Captures both a date and a time in a single combined response. | Date and Time | + + +

+To learn more about date and time questions in KoboToolbox, see Date and Time question types. +

+ +### Calculate and hidden question types + +Calculate and hidden questions are used to perform automatic calculations within a form based on previous responses or to store predefined values. + +| XLSForm type | Description | Formbuilder equivalent | +| :--- | :--- | :--- | +| `calculate` | Automatically performs calculations within a form based on responses to previous questions. | Calculate | +| `hidden` | Stores predefined values that are not visible to the respondent. The value is stored in the **default** column. | Hidden | + +To learn more about calculations in the Formbuilder, see Calculate question type. To learn more about calculations in XLSForm, see Adding calculations in XLSForm. + +

+For hands-on practice with different question types XLSForm, see KoboToolbox Academy's XLSForm Fundamentals Course. +

diff --git a/source/repeat_groups_xls.md b/source/repeat_groups_xls.md new file mode 100644 index 000000000..4f03d2e8c --- /dev/null +++ b/source/repeat_groups_xls.md @@ -0,0 +1,182 @@ +# Repeat groups in XLSForm + +Repeat groups in XLSForm allow you to ask the same set of questions multiple times within a form. This is especially useful when collecting similar information about several people, items, or events. + +For example, if you're gathering details about each member of a household, you can use a repeat group to ask the same demographic questions for every individual. + +This article covers the following topics: +- Creating a repeat group +- Setting repeat counts to limit the number of repetitions +- Counting the number of repetitions within a repeat group +- Retrieving values from repeat groups + +

+Note: This article focuses on repeating groups in XLSForm. To learn about repeating groups in the KoboToolbox Formbuilder and to preview repeat groups in action, see Grouping questions and repeating groups. +

+ +## Creating a repeat group + +To create a repeat group in XLSForm: + +1. In the `type` column of the survey worksheet, enter **begin_repeat** to indicate the start of the repeat group. +2. In the `name` column of the **begin_repeat** row, enter the unique identifier for the group. +3. In the `label` column, enter the title of the group as you want it displayed in the form. The label is optional and can be left blank. +4. Enter each question of the group in its own row, as you normally would. +5. In a new row after the repeating questions, enter **end_repeat** in the `type` column to indicate the end of the repeat group. + - In the **end_group** row, leave the `name` and `label` columns blank. + +**survey worksheet** + +| type | name | label | +| :--- | :--- | :--- | +| **begin_repeat** | household_members | Household Members | +| text | name | What is the person's name? | +| integer | age | How old are they? | +| select_one yn | married | Are they married? | +| **end_repeat** | | | +| survey | + +Repeat groups function similarly to question groups. With repeat groups, you can: + +- Use the **field-list** appearance to [display all questions](https://support.kobotoolbox.org/grouping_questions_xls.html#appearance-settings-for-question-groups) on the same page. +- Add [skip logic](https://support.kobotoolbox.org/grouping_questions_xls.html#applying-skip-logic-to-question-groups) to repeat groups in the **relevance** column. +- Create **nested** repeat groups, where one repeat group is added [inside another](https://support.kobotoolbox.org/grouping_questions_xls.html#nested-groups). + +

+ Note: Adding repeat groups to your form creates a different data structure compared to standard variables or groups. When you download your data in .xlsx format, you will find a separate sheet for each repeat group. For more information on exporting and using repeat group data, see Managing repeat group data. +

+ +## Setting repeat counts + +By default, repeat groups can be repeated as many times as needed. To limit the number of times a repeat group is repeated in the form, you can set a repeat count. The **repeat count** can be either a fixed number or dynamically determined based on a previous response. + +To set a fixed number of repetitions: + +1. Add a **repeat_count** column in the `survey` worksheet. +2. Input a number in the **repeat_count** column. + +**survey worksheet** + +| type | name | label | repeat_count | +| :--- | :--- | :--- | :--- | +| begin_repeat | participant_profile | Participant profile | 3 | +| text | name | Name | | +| select_one gender | gender | Gender | | +| integer | age | Age | | +| end_repeat | | | | +| survey | + +To dynamically determine the number of repetitions based on a previous response: + +1. Add a **repeat_count** column in the `survey` worksheet. +2. Enter the question reference in the **repeat_count** column. + - The referenced question must be an `integer` question type. + + **survey worksheet** + +| type | name | label | repeat_count | +| :--- | :--- | :--- | :--- | +| integer | participants | Total number of training participants | | +| begin_repeat | participant_profile | Participant profile | ${participants} | +| text | name | Name | | +| select_one gender | gender | Gender | | +| integer | age | Age | | +| end_repeat | | | | +| survey | + +

+ Note: Inside the repeat_count column, you can also include advanced conditional statements to determine if repetitions will continue. For more information, see ODK documentation. +

+ +## Counting number of repetitions inside a repeat group + +When using repeat groups, you may need a field that counts how many times the group has been repeated. This can be useful for calculations or form logic. For example, you can apply skip logic after a specific repetition or dynamically include the repeat number in a question label (e.g., Child 1, Child 2). + +To count how many times a repeat group has been repeated: +1. Add a **calculate** question inside the repeat group. +2. Enter `position(..)` in the **calculation** column. + +This variable stores the current repeat index. You can use it in form logic or to create dynamic question labels. + +**survey worksheet** + +| type | name | label | calculation | relevance | +| :--- | :--- | :--- | :--- | :--- | +| begin_repeat | profile | Participant profile | | | +| calculate | number | | **position(..)** | | +| note | instructions | Answer the questions below for each participant. | | **${number} = 1** | +| text | name | Name of participant **${number}** | | | +| select_one gender | gender | Gender of participant **${number}** | | | +| integer | age | Age of participant **${number}** | | | +| end_repeat | | | | | +| survey | + +## Counting total number of repeat group repetitions + +You can also add a separate question outside the repeat group to count the total number of repetitions. This is useful, for example, to confirm the number of participants or children listed in the repeat group. + +To count how many times a repeat group was filled in: +1. Add a **calculate** question after the repeat group. +2. In the **calculation** column, enter `count(${repeat_group_name})`, where `repeat_group_name` is the name of the repeat group. + +This variable stores the total number of group repetitions. You can use it in calculations or to create dynamic question labels in your form. + +**survey worksheet** + +| type | name | label | calculation | +| :--- | :--- | :--- | :--- | +| begin_repeat | children | Children roster | | +| text | name | Name | | +| select_one gender | gender | Gender | | +| integer | age | Age | | +| end_repeat | | | | +| calculate | count_children | | **count(${children})** | +| acknowledge | confirm_children | Confirm that there are **${count_children}** children in the household. | | +| survey | + +## Retrieving values from repeat groups + +Advanced forms often use [question referencing](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing) to include responses from earlier questions in question labels, calculations, or skip logic. You can also use question referencing **within repeat groups** or to refer to repeated data elsewhere in your form. + +Within a repeat group, you can reference a response from another question in the same repetition using question referencing, as shown below. + +**survey worksheet** + +type | name | label | +| :--- | :--- | :--- | +| begin_repeat | children | Children roster | +| text | name | What is the child's name? | +| integer | age | How old is ${name}? | +| select_one gender | married | What is ${name}'s gender? | +| end_repeat | | | +| survey | + +Outside a repeat group, you can retrieve data from the repeat group for use in form logic or question labels: + +1. Add a **calculate** question after your repeat group. +2. Include one of the formulas listed below in the **calculation** column. +3. The **calculate** question stores the retrieved value, which you can then use in form logic or question labels. + +**Formulas to retrieve data from repeat groups** + +| Formula | Description | +| :--- | :--- | +| `max(${question-name})` | Retrieves the maximum value entered for one question in the repeat group. | +| `min(${question-name})` | Retrieves the minimum value entered for one question in the repeat group. | +| `sum(${question-name})` | Computes the sum of numerical values entered for one question in the repeat group. | +| `join('; ', ${question-name})` | Lists all responses to a given question inside a repeat group, separated by a semi-colon. | +| `indexed-repeat(${question-name}, ${repeat-name}, n)` | Retrieves the value for `${question-name}`, in the repeat group called `${repeat-name}`, in the nth repetition. | + +**survey worksheet** + +| type | name | label | calculation | +| :--- | :--- | :--- | :--- | +| begin_repeat | children | Children roster | | +| text | name | Name | | +| select_one gender | gender | Gender | | +| integer | age | Age | | +| end_repeat | | | | +| calculate | max_age | | **max(${age})** | +| acknowledge | confirm_age | Confirm that the oldest child in the household is **${max_age}** years old. | | +| survey | + diff --git a/source/required_logic_xls.md b/source/required_logic_xls.md new file mode 100644 index 000000000..c935e2d43 --- /dev/null +++ b/source/required_logic_xls.md @@ -0,0 +1,68 @@ +# Adding required logic in XLSForm + +Required logic allows you to make a question mandatory if specific conditions are met. For example, you can require a phone number question only if respondents agree to be contacted in the future. This option provides more control than simply marking a question as always required or always optional. + +

+ To learn more about required questions and how to customize the message shown to respondents when they leave a required question unanswered, see Using question options in XLSForm. +

+ +This article explains how to add required logic conditions in XLSForm, including making a question required based on whether another question was answered. + +

+ Note: This article focuses on adding required logic in XLSForm. To learn about adding required logic in the KoboToolbox Formbuilder, see Using the question options. +

+ For hands-on practice with required logic in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Adding required logic conditions + +Required logic uses question referencing to make questions required based on previous answers. The question used to define the required logic is referred to as the **reference question.** + +To add required logic in XLSForm: +1. Add a **required** column to the `survey` worksheet. +2. In the row of the question you wish to set the required logic for, enter the condition that must be met in order **for the question to be mandatory.** + +**survey worksheet** + +| type | name | label | required | +|:--------------|:-----------|:--------------------------------------------------------------------------|:------------------| +| select_one yn | recontact | Do you agree to being contacted again for another study in the future? | | +| text | email | What is your email address? | ${recontact} = 'yes' | +| survey | + +If a respondent does not answer a required question, they will not be able to proceed to the next page of the form or submit it. + +### Formatting required logic conditions + +The format of the required logic condition will differ according to the **type** of the reference question, as detailed in the table below. + +| Reference question type | Required logic condition | Example | +|:-------------------------|:--------------------|:---------| +| select_one | `${reference_question} = 'choice_name'` | `${consent} = 'yes'` | +| select_multiple | `selected(${reference_question}, 'choice_name')` | `selected(${reasons}, 'other')` | +| integer | `${reference_question}` followed by a logical operator (>, <, =) and a number (or a reference to another question) | `${age} >= 18` | +| date | `${reference_question}` followed by a logical operator (>, <, =) and `date('YYYY-MM-DD')` | `${dob} >= date('1975-01-01')` | + +

+To learn more about building form logic expressions in XLSForm, see Introduction to form logic in XLSForm. +

+ +## Adding required logic based on whether a question was answered + +In addition to setting required logic for a specific response, you can also base it on whether a question was answered or left blank. This is useful when you want to ensure that at least one of two questions is required. + +Unanswered questions are treated as empty strings, noted as two single apostrophes `''`. The following required logic conditions can be used: + +| Required logic condition | Description | +|:---------------------------|:-------------| +| `${reference_question} != ''` | Require only if `reference_question` is answered (not blank). | +| `${reference_question} = ''` | Require only if `reference_question` is unanswered (blank). | + +**survey worksheet** + +| type | name | label | required | +|:------|:--------|:----------------------------------------------------|:-------------| +| note | contact | Please provide your phone number or email address below. | | +| text | phone | Phone number | | +| text | email | Email address | ${phone} = '' | +| survey | diff --git a/source/select_from_file_xls.md b/source/select_from_file_xls.md new file mode 100644 index 000000000..13b75891c --- /dev/null +++ b/source/select_from_file_xls.md @@ -0,0 +1,86 @@ +# Selecting options from an external file + +**Select from file** questions allow you to use a list of choice options stored in an external file instead of defining them directly in your form. There are two types: `select_one_from_file` for selecting a **single choice**, and `select_multiple_from_file` for selecting **multiple choices**. + +Using a separate file for your choice list makes it easier to manage long lists, reuse them across multiple forms, and update options when needed. Supported file formats include CSV, XML, and GeoJSON. + +This article explains how to format your external file, set up your XLSForm to use **select from file** questions, and upload your external file to KoboToolbox. + +

+Note: This article focuses on adding select from file questions in XLSForm. To learn about adding select from file questions in the KoboToolbox Formbuilder, see Select One or Many From External File Question Type. +

+ For hands-on practice with select from file questions in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Formatting external choice lists + +To get started, create your list of choices in a separate external file. The required structure of this file depends on the format you choose (CSV, XML, or GeoJSON). Use a separate file for each choice list. + +

+ To learn more about formatting XML or GeoJSON files, see XLSForm and ODK documentation. GeoJSON files are primarily used for selecting options from a map. +

+ +For CSV files, the structure is similar to the choices worksheet in an XLSForm. It should include the `name` and `label` columns, but the `list_name` column is not needed. + +**External CSV file** + +| name | label | +|:--------|:----------| +| option1 | Option 1 | +| option2 | Option 2 | +| option3 | Option 3 | + +If your file uses different names for the choice name and label, you can specify this in your XLSForm (see instructions [below](https://support.kobotoolbox.org/select_from_file_xls.html#configuring-choice-name-and-label-columns)). + +

+Note: Use short, simple file names for your external files, avoiding spaces or special characters. The file name will be used in your XLSForm to link questions to their choice lists. If you use multiple external files, make sure each one has a unique name, even if they use different file types. +

+ +## Setting up your XLSForm + +To add a select from file question to your XLSForm: +1. In the `type` column of the `survey` worksheet, enter the select from file question type (`select_one_from_file` or `select_multiple_from_file`). +2. In the same cell, instead of the choices `list_name`, add a single space and the name of the external file, including the file extension. + - For example: `select_one_from_file households.csv` + +**survey worksheet** + +| type | name | label | +|:-------------------------|:-----|:----------------| +| select_one_from_file households.csv | hh | Select household | +| survey | + +### Configuring choice name and label columns + +If your external file uses different column names instead of `name` and `label`: +1. Add a **parameters** column to the `survey` worksheet +2. In the select from file question row, specify the custom names with the `value` and `label` parameters. + - `value` represents the choice **name**. + - `label` represents the choice **label**. + +**survey worksheet** + +| type | name | label | parameters | +|:-------------------------|:-----|:-----------------|:-----------------------------| +| select_one_from_file households.csv | hh | Select household | value=housenum label=housename | +| survey | + +## Uploading the external file to KoboToolbox + +When uploading your XLSForm to KoboToolbox, you must also upload the external file that contains your list of choices: +1. In KoboToolbox, navigate to the project **SETTINGS** page. +2. In the **Media** tab, upload the external file. Ensure the file name matches exactly the file name specified in the XLSForm. + +To update your list of choices, edit the external file as needed, re-upload it to KoboToolbox, and redeploy your form. + +![Upload media](images/select_from_file_xls/upload_media.png) + +## Troubleshooting + +
+ Translated choice lists + Select from file questions do not currently support translated choice lists. Your external choice file can include only a single label column. Any additional translated label columns will be ignored in Enketo or will cause an error in KoboCollect. For forms that include translations, use internal choice lists instead, or set up multiple select from file questions using skip logic to pull from different files depending on the form language. +
+ + + diff --git a/source/select_from_map_xls.md b/source/select_from_map_xls.md new file mode 100644 index 000000000..c99b450c3 --- /dev/null +++ b/source/select_from_map_xls.md @@ -0,0 +1,116 @@ +# Selecting options from a map + +With **select_one** and **select_one_from_file** question types, you can configure your XLSForm to let users select a choice directly from a map instead of a list. When the map opens, it displays all available points, lines, or polygons based on the choices provided. Users can then tap a feature on the map to record their selection. This functionality is available **only in KoboCollect.** + +This article explains how to configure your XLSForm to allow selecting options from a map, how to customize styling options such as colors, symbols, and line widths, and how choices are displayed and selected on the map. + +

+Note: The KoboToolbox Formbuilder does not support map-based selection for the select_one question type. To use this feature, configure it in an XLSForm and upload the form to KoboToolbox. +

+ To learn more about downloading and editing your form as XLSForm, see Using XLSForm with KoboToolbox. +

+ +## Setting up your XLSForm + +To set up a **select from map** question in XLSForm: +1. In the `survey` worksheet, add a `select_one` or `select_one_from_file` question. +2. Add an `appearance` column. +3. In the `appearance` column of the select question, enter **map** or **quick map.** + - The **map** appearance allows respondents to click on different locations and view information about each before confirming their selection. + - The **quick map** appearance automatically records the first selected location without displaying additional information. + +**survey worksheet** + +| type | name | label | appearance | +|:------------|:---------|:----------------------------|:-----------| +| select_one | location | Where are you currently based? | map | +| survey | + +4. In the `choices` worksheet or in your [external list of choices](https://support.kobotoolbox.org/select_from_file_xls.html), enter the choices as you normally would. +5. Next to your choice list, add a **geometry** column. +6. For each choice, enter the corresponding GPS coordinates in the **geometry** column. + - This field can include unique or multiple GPS coordinates, to define a point, a line, or a polygon. + +**choices worksheet** + +| list_name | name | label | geometry | +|:----------|:-----|:-------|:------------------| +| cities | 1 | Warsaw | 52.2297 21.0122 0 0 | +| cities | 2 | Berlin | 52.5200 13.4050 0 0 | +| cities | 3 | Paris | 48.8566 2.3522 0 0 | +| cities | 4 | Kyiv | 50.4501 30.5234 0 0 | +| cities | 5 | Prague | 50.0755 14.4378 0 0 | +| choices | + +### Format of GPS coordinates + +When entering GPS coordinates in the `choices` worksheet or an external CSV or XML file, the following format must be used: `longitude latitude altitude accuracy`. + +- For example, the GPS coordinates for Paris would be `48.8566 2.3522 0 0`. + +When providing multiple GPS coordinates (e.g., for a line or polygon), coordinates are separated by a semicolon. +- For example, the GPS coordinates for a line going from Paris to Madrid would be `48.8566 2.3522 0 0;40.4637 -3.6556 0 0`. +- For a polygon, the GPS coordinates must start and end with the same coordinates. + +

+Note: To obtain your GPS coordinates in the correct format, you can use this KoboToolbox form. It lets you select points on a map and automatically generates the corresponding GPS coordinates in ODK format. +

+ +If you are using a GeoJSON file to provide GPS coordinates, follow the [GeoJSON format](https://docs.getodk.org/form-datasets/#selects-from-geojson) to specify the feature `geometry` . + +

+ For an example of map-based select questions, see this sample XLSForm. External choice files for upload to KoboToolbox are available here (CSV), here (GeoJSON), and here (XML). To learn more about using external choice files, see Selecting options from an external file. +

+ +## Adding choice properties + +You can further customize your map by adding choice properties in the `choices` worksheet or external choice file. + +Available choice properties include: + +| Choice property | Description | +|:----------------|:------------| +| `info` | Text description of the choice. | +| `marker-color` | HEX color for the geopoint marker. | +| `marker-symbol` | Single character, symbol, or emoji displayed on the geopoint marker. | +| `stroke` | HEX color for the geotrace line or the geoshape polygon outline. | +| `stroke-width` | Width of the geotrace line or the geoshape polygon outline (e.g., 5 or 6.5). | +| `fill` | HEX color for the polygon interior. The fill color is displayed with fixed transparency. | + +To add properties in the `choices` worksheet of your XLSForm: + +1. Add a column with the appropriate property name (e.g., `info`, `stroke`, or `fill`). +2. For each choice, enter the corresponding value (e.g., a text description or a HEX code) + +**choices worksheet** + +| list_name | name | label | geometry | info | +|:----------|:-----|:-------|:------------------|:---------------------------| +| cities | 1 | Warsaw | 52.2297 21.0122 0 0 | Capital of Poland | +| cities | 2 | Berlin | 52.5200 13.4050 0 0 | Capital of Germany | +| cities | 3 | Paris | 48.8566 2.3522 0 0 | Capital of France | +| cities | 4 | Kyiv | 50.4501 30.5234 0 0 | Capital of Ukraine | +| cities | 5 | Prague | 50.0755 14.4378 0 0 | Capital of Czech Republic | +| choices | + +If you are using a GeoJSON file to provide GPS coordinates, follow the [GeoJSON format](https://docs.getodk.org/form-datasets/#selects-from-geojson) to specify feature `properties`. + +## Map selection in KoboCollect + + + +

+Note: Selecting options from a map is only available in KoboCollect. In Enketo web forms, the option choices will appear as a normal list of options. +

+ +In KoboCollect, adding a **select type question** with a **map** or **quick map** appearance allows users to choose an option directly from a map rather than from a list. When the map opens, it centers on the device’s current location. Buttons on the right let users recenter on their location or show all available map points. + +Point choices are shown as map markers. Tapping a marker increases its size. +Line and polygon choices are displayed as red outlines, with polygons shaded in red. Users can tap a line or polygon to select it. When a location is selected, its [properties](https://support.kobotoolbox.org/select_from_map_xls.html#adding-choice-properties) appear at the bottom of the screen, unless the **quick map** appearance is used. + +Under the choice label, a **Select** button appears to confirm and save the selected location to the form, unless the **quick map** appearance is used. + +

+Note: The map and quick map appearances can be combined with choice filters to display options on the map based on a previous selection. +

+ diff --git a/source/skip_logic_xls.md b/source/skip_logic_xls.md new file mode 100644 index 000000000..b74b45955 --- /dev/null +++ b/source/skip_logic_xls.md @@ -0,0 +1,110 @@ +# Adding skip logic in XLSForm + +Skip logic, also known as relevance logic, allows you to **determine when a question or group of questions will be displayed** in the form based on a previous question or the result of a calculation. For example, you can use it to ask follow-up questions only to a subset of respondents, or to hide entire sections of a form if they are not relevant. + +

+ To learn more about form logic in XLSForm, see Introduction to form logic in XLSForm. +

+ +This article covers the following topics: +- Adding skip logic to individual questions +- Combining multiple skip logic conditions +- Adding skip logic based on whether a question was answered +- Adding skip logic to question groups + +

+ Note: This article focuses on adding skip logic in XLSForm. To learn about adding skip logic in the KoboToolbox Formbuilder, see Adding skip logic in the Formbuilder. +

+For hands-on practice with skip logic in XLSForm, see KoboToolbox Academy’s XLSForm Fundamentals Course. +

+ +## Adding skip logic conditions to individual questions + +Skip logic uses [question referencing](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing) to only display questions that are relevant to the respondent based on previous answers. The question used to define the relevance logic is referred to as the **reference question**. + +To add skip logic in XLSForm: +1. Add a **relevant** column to the `survey` worksheet. +2. In the row of the question you wish to display or hide, enter the condition that must be met **for the question to be displayed.** + +**survey worksheet** + +| type | name | label | relevant | +|:--------------|:----------|:------------------|:--------------| +| integer | age | How old are you? | | +| select_one yn | married | Are you married? | ${age} > 18 | +| survey | + +In the example above, `${age}` is the reference question, and the answer to `${age}` must be greater than 18 for the “Are you married?” question to be displayed. + +### Formatting skip logic conditions + +The format of the skip logic condition will differ according to the **type** of the reference question, as detailed in the table below. + +| Reference question type | Skip logic condition | Example | +|:-------------------------|:--------------------|:---------| +| select_one | `${reference_question} = 'choice_name'` | `${consent} = 'yes'` | +| select_multiple | `selected(${reference_question}, 'choice_name')` | `selected(${reasons}, 'other')` | +| integer | `${reference_question}` followed by a logical operator (>, <, =) and a number (or a reference to another question) | `${age} >= 18` | +| date | `${reference_question}` followed by a logical operator (>, <, =) and `date('YYYY-MM-DD')` | `${dob} >= date('1975-01-01')` | + +

+ To learn more about building form logic expressions in XLSForm, see Introduction to form logic in XLSForm. +

+ +## Combining multiple skip logic conditions + +Multiple relevance conditions can be combined into a single expression to determine when a question is displayed based on a previous response. Conditions can be combined using **and**, **or**, and **not** logical operators: + +- Use **and** when all conditions must be met for a question to be displayed. + - For example: ${age} > 18 and ${student} = ‘no’ +- Use **or** when at least one condition must be met for a question to be displayed. + - For example: ${age} < 18 or ${student} = ‘yes’ +- Use **not** to indicate that a condition or set of conditions must not be met (e.g., when two conditions cannot be true together for a question to be displayed). + - For example: not(${age} > 18 and ${student} = ‘yes’) + +**survey worksheet** + +| type | name | label | relevant | +|:--------------|:----------|:-------------------|:----------------------------------| +| integer | age | What is your age? | | +| select_one yn | employed | Are you employed? | ${age} >= 16 and ${age} <= 75 | +| survey | + +## Adding skip logic based on whether a question was answered + +In addition to adding skip logic based on a specific response, you can add skip logic based on whether a question was answered or left blank. This can be useful to add follow-up questions, or when using [acknowledge questions](https://support.kobotoolbox.org/acknowledge.html) in your form. + +Unanswered questions are treated as empty strings, noted as two single apostrophes `''`. The following skip logic conditions can be used: + +| Skip logic condition | Description | +|:---------------------|:-------------| +| `${reference_question} != ''` | Display only if `reference_question` is answered (not blank). | +| `${reference_question} = ''` | Display only if `reference_question` is unanswered (blank). | + +**survey worksheet** + +| type | name | label | relevant | +|:--------------|:-----------|:---------------------|:---------------------| +| text | why_joined | Why did you join? | | +| select_one yn | benefits | Are you seeing benefits? | ${why_joined} != '' | +| survey | + +## Adding skip logic conditions to question groups + +Skip logic can be applied to question groups as well as individual questions. Applying skip logic to a group will show or hide all questions within that group based on previous responses. + +To add skip logic to question groups: +1. Add a **relevant** column to the `survey` worksheet. +2. In the **begin_group** row of the question group you wish to display or hide, enter the condition that must be met **for the group to be displayed.** + +**survey worksheet** + +| type | name | label | relevant | +|:-------------|:------------|:---------------------------------------------|:-------------------| +| select_one yn | joined | Did you join the association? | | +| begin_group | association | Association participation | ${joined} = 'yes' | +| date | date_joined | When did you join the association? | | +| select_one yn | voted | Have you ever voted in any election for the association? | | +| end_group | | | | +| survey | + diff --git a/source/xlsform_with_kobotoolbox.md b/source/xlsform_with_kobotoolbox.md new file mode 100644 index 000000000..1df023f5d --- /dev/null +++ b/source/xlsform_with_kobotoolbox.md @@ -0,0 +1,180 @@ +# Using XLSForm with KoboToolbox +**Last updated:** Oct 7, 2025 + +XLSForm integrates smoothly with Kobo Toolbox for creating, previewing, +editing, and deploying forms for data collection. For example, you can start +building a form in the Kobo Toolbox Formbuilder, then download it as an +XLSForm for further customization. This provides a structured foundation, +useful for new projects or users with less form building experience. + +Once customized, forms created in XLSForm can be uploaded to Kobo Toolbox +for review, modification, and deployment. + +This article covers the following topics: +- Downloading an XLSForm from Kobo Toolbox +- Upload and previewing an XLSForm in Kobo Toolbox +- Replacing an existing form with an XLSForm +- Importing an XLSForm via URL +- Testing and validating your XLSForm + +## Downloading an XLSForm from KoboToolbox + +When working in KoboToolbox, you may need to download your form as an +XLSForm to make changes more efficiently, such as duplicating many +questions, editing large option lists, adding translations, or using advanced +functionalities not available in the Formbuilder. Additionally, downloading your +form as an XLSForm allows you to build forms offline, share them as `.xlsx` +files for collaboration and version management, and share them with the +Kobo Toolbox support team or in the Community Forum to request assistance. + +Any form created using the KoboToolbox Formbuilder can be downloaded as +an XLSForm file: + +1. Go to the **FORM** page of your project in KoboToolbox. +2. Click the **More actions** icon. +3. Select **Download XLS**. + +![Download XLS menu](images/xlsform_with_kobotoolbox/download_xls.png) + +## Uploading an XLSForm to KoboToolbox +Alternatively, you may need to create a new project from an XLSForm that you +have created from scratch or that has been shared with you. + +To upload and preview an XLSForm to a new project in KoboToolbox: + +1. Go to the **Projects** home page in KoboToolbox and click **NEW**. +2. Select **Upload an XLSForm** and upload your Excel file. +3. Enter the project details and click **Create project**. +4. Click the **Preview** button to preview + your form. + +![Upload XLSForm dialog](images/xlsform_with_kobotoolbox/upload_xls.png) + +## Replacing a form with an XLSForm +Once a project has been created, you can replace any existing form with an +updated XLSForm: + +1. Go to the **FORM** page of your project in KoboToolbox. +2. Click **Replace form** in the top right + corner. +3. Select **Upload an XLSForm** and upload your Excel file. + +![Replace form source dialog](images/xlsform_with_kobotoolbox/replace_form.png) + +## Importing an XLSForm via URL +If you are using Google Sheets or storing the file in Dropbox, you can import +an XLSForm via a URL. The URL must be publicly accessible and should +initiate a file download when opened in a browser for the import to work. +XLSForms can also be imported from similar software, such as Excel Web and +OneDrive. + +
Retrieving a link from Google Sheets + +To obtain the correct URL for a Google Sheets spreadsheet: + +1. Click on **File > Share > Publish to the Web**. +2. Under the **Web Page** dropdown menu, select **Microsoft Excel (.xlsx)**. Keep + **Entire Document** selected in the first dropdown. +3. Click **Publish**. +4. Copy the resulting document link. + +

+For more information, see Google Sheets documentation. +

+ +
+ +
+ +
Retrieving a link from Dropbox + +To obtain the correct URL for a spreadsheet stored in Dropbox: + +1. Copy the file link in Dropbox by clicking on **Copy link**. +2. At the end of the link, replace the suffix ``dl=0`` with ``dl=1``. This will be the + URL to import into Kobo Toolbox. + +
+ +
+ +Once you have retrieved the file URL, you can import your XLSForm to +KoboToolbox: + +1. Go to the **Projects** homepage in Kobo Toolbox and click **NEW**. +2. Select **Import an XLSForm via URL**. +3. Paste your URL and click **Import**. +4. Enter the project details and click **Create project**. + +![Import XLSForm via URL dialog](images/xlsform_with_kobotoolbox/import_via_url.png) + +

+ Note: Changes made to a file in Dropbox or Google Sheets do not + automatically update in Kobo Toolbox. You must re-import the XLSForm via + URL and redeploy the form changes. +

+ +## Testing and validating your XLSForm +Validating, previewing, and testing your XLSForm is essential to ensuring its +structural integrity, functionality, and user experience. Each of these steps +help identify any errors or issues that might prevent the form from functioning +as intended. + +| Step | Description | +| :--- | :--- | +| Validating | This involves uploading the form and checking for errors (e.g., spelling or capitalization mistakes, incorrect form logic expressions, incorrect question referencing, missing labels). Form error messages typically appear when uploading, deploying, or opening a form. | +| Previewing | This allows you to visualize the form as it will be displayed to respondents and verify that all elements function correctly before deployment (e.g., form layout, question and choice labels). | +| Testing | This involves entering data to test form functionality (e.g., checking question appearances, choice options, and form logic). Testing can be done in **PREVIEW** mode before deployment. | + +Continuously validating and testing your XLSForm as you make changes will +simplify troubleshooting and help identify the cause of any issues. It is crucial +to ensure your form functions as expected before launching data collection. + +There are several tools available to test your XLSForm, including the KoboToolbox platform, the [KoboCollect app](https://play.google.com/store/apps/details?id=org.koboc.collect.android), and [ODK's XLSForm Online](https://getodk.org/xlsform/). When +previewing and testing your form, use the same platform that you will use for +data collection: [Enketo web forms](https://support.kobotoolbox.org/enketo.html), [KoboCollect](https://support.kobotoolbox.org/kobocollect_on_android_latest.html), or both. + +

+To learn more about setting up KoboCollect to preview and test your forms, see +Getting started with KoboCollect. +

+ +## Troubleshooting + +
+Error message when uploading, previewing, or deploying XLSForm + +If your XLSForm contains an error, an error message will appear, usually +indicating the exact row, question, or expression where the issue is located. After +correcting the error in your spreadsheet, you will need to upload the file again. + + +| **Common error messages** | **Common explanation** | +| :--- | :--- | +| `The survey sheet is either empty or missing important column headers.` | Mandatory column headers are missing or misspelled. | +| `The survey element named 'name' has no label or hint.` | One of the questions in your form is missing a question label. | +| `FormLogicError: Could not evaluate: [expression], message: The string did not match the expected pattern.` | A form logic expression contains errors, such as incorrect question referencing syntax or a missing parenthesis. | +| `unable to deploy ODK Validate Errors: >> XForm is invalid` | A form logic expression contains errors, such as incorrect question referencing syntax or a missing parenthesis. | +| `There has been a problem trying to replace ${question with the XPath to the survey element named 'question'. There is no survey element with this name.` | You are referring to a question in your form that does not exist or is misspelled. Ensure you are using the **exact** question name in your form logic expressions. | +| `list_name` | The option list for a question has not been defined, or there is a typo in the `list_name`. | +| `Choice names must be unique for each choice list. If this is intentional, use the setting 'allow_choice_duplicates'.` | Duplicate choice names have been used within the same list of options. Remove the duplicated choice name(s), or allow choice duplicates in your form settings. | +| `Unmatched begin statement: group (group)` | Question group is missing its corresponding `end_group` row. | +| `Can't find external_file.csv` | An external attachment linked to your form (e.g., when using `pulldata()` ) has not been uploaded to KoboToolbox. | +| `Can't find survey.xml` | Dynamic data attachments have not been properly set up in your project settings. | +
+ +
+ +
+Error when trying to import an XLSForm via URL +
+Check that the URL you are using is correct. When loaded into a browser, the URL should initiate a file download, not open a webpage. +
+ +
+ +
+Import via URL not loading undeployed version +
+If you imported a link and are not seeing the new form version, refresh your browser. +