Select from file
select_one_from_file and select_multiple_from_file load choices dynamically from an external CSV or XML file attached to the form.
select_one_from_file and select_multiple_from_file work like select_one and select_multiple, but instead of defining choices in the choices worksheet, the choices are loaded from an external CSV or XML file attached to the form. This is useful when your choice list is very long, changes frequently, or needs to be updated without rebuilding the entire form.
Basic XLSForm Specification
| type | name | label |
|---|---|---|
| select_one_from_file health_facilities.csv | facility | Select the health facility |
| select_multiple_from_file crops.csv | crops | Which crops does the household grow? |
The filename after the type name must match the name of the file you attach when uploading the form.
CSV file format
Your CSV file must have at least two columns: name (the stored value) and label (the displayed text). You can add any number of extra columns for filtering.
health_facilities.csv:
name,label,district,type
HF001,Nairobi Central Clinic,Nairobi,clinic
HF002,Westlands Health Centre,Nairobi,health_centre
HF003,Kisumu District Hospital,Kisumu,hospital
Filtering choices
Use the choice_filter column to show only the choices that match the current context. Reference CSV columns with their column name directly (no ${}):
| type | name | label | choice_filter |
|---|---|---|---|
| select_one districts.csv | district | Select district | |
| select_one_from_file health_facilities.csv | facility | Select facility | district = ${district} |
In this example, only facilities in the selected district are shown. The district in choice_filter refers to the district column in the CSV file; ${district} refers to the form field named district.
Uses
Select-from-file questions are commonly used for:
- Long choice lists — health facilities, schools, villages, species lists (hundreds or thousands of items)
- Frequently updated lists — when the master list changes between survey rounds, update only the CSV without rebuilding the form
- Shared reference data — one CSV file used across multiple forms
- Filtered cascading selects — load all regions/districts/villages in one file, then filter by the parent selection
Attaching the file
When you upload your form to rtSurvey, attach the CSV file as a media attachment. The filename in the form definition must exactly match the filename of the attachment.
File names are case-sensitive. Health_Facilities.csv and health_facilities.csv are treated as different files.
Using choice-label() with from-file
To display the label of a selected choice in a note or calculate field:
| type | name | label | calculation |
|---|---|---|---|
| select_one_from_file health_facilities.csv | facility | Select facility | |
| calculate | facility_label | choice-label(${facility}, ${facility}) | |
| note | summary | Selected facility: ${facility_label} |
Best Practices
- Keep your CSV files under 5,000 rows for good performance on mobile devices.
- Always include a
nameandlabelcolumn — additional columns are optional. - For cascading selects, use a single CSV with a parent column and filter with
choice_filter. - Version your CSV filenames (e.g.,
facilities_v3.csv) when making breaking changes to the column structure. - Test filtering expressions carefully — a typo in
choice_filterwill silently show no choices.
Limitations
- Very large CSV files (10,000+ rows) can slow down form loading, especially on low-end devices.
- CSV files must be uploaded together with the form — they cannot be fetched from a URL at runtime (use
search()orpulldata()for dynamic lookups). select_multiple_from_fileis less commonly supported across clients — verify compatibility before using it.
Comparison with search()
select_one_from_file | search() appearance | |
|---|---|---|
| Choices source | Attached CSV/XML file | Server-side database query |
| Works offline | Yes (file is bundled) | Requires connectivity |
| Choice count | Limited by device memory | Unlimited (paginated) |
| Real-time data | No | Yes |
For large, frequently changing, or server-side datasets, see Dynamic search.