Fill a text field with a preset value based on the selected value of a list in XLS Forms

429 views Asked by At

I am building an xlsx form for ODK. I have a dropdown list and a text-input field. I would like when I select a value from the ListA, a specific code to be filled in the text-input field.

For example if I choose "valueA" from the dropdown list the value "codeA" to appear in the text-input. Currently I have an excel sheet with all the matches between the values in ListA and the corresponding codes (around 300). All the values in ListA are unique.

I was making some tests trying to use the "Calculation" field of Xls but no success till now. Has anyone done something like that with Xls? Is it possible?

1

There are 1 answers

0
Luise On

You could include a calculate field between the dropdown list and the text-input where you pull values from a csv file with the correspondence between valueA and codeA using the value selected in ValueA as a key. You can find an explanation of how the pulldata(...) calculation works here.

Here goes a brief example. In the survey tab:

|type           |name   |label                  |calculation|

|select_one keys|value_a|Value A                |           |
|calculate      |code_a |                       |pulldata('data', 'value_column', 'key_column', ${value_a}|
|note           |note   |Code A value: ${code_a}|           |

enter image description here

In the choices tab:

|list_name|name    |label   |

|keys     |valueA_1|valueA_1|
|keys     |valueA_2|valueA_2|
(.......)

enter image description here

And the file data.csv should look like this:

|value_column|key_column|

|valueA_1    |codeA_1   |
|valueA_2    |codeA_2   |
(.......)

enter image description here

Finally, I would advice to consider applying a cascade selection layout in value_a, because selecting one out of 300 values can be challenging. Another option could be sorting these choices alphabetically or in a different order, such that when someone fills-in your form she will know how to easily locate the appropriate choice.

Hope this helps!