ibrigadir / opendatakit

Automatically exported from code.google.com/p/opendatakit
0 stars 0 forks source link

choice-name not working with a dynamic choice-list is accessed from csv #1153

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Reported by Andrew <acawood777@gmail.com>
-------------------
Hi all,

I am having problems using choice-name() within a repeat-group when data has 
been loaded from a csv:

First I load data from a csv to populate a multi-select.
Once selections have been made I have a repeat-group which repeats for each 
selection (e.g. 3 items selected = 3 repeats)
Each repeat needs to display the corresponding name and label that was 
selected, in order to request further info on each.

For the name I use selected-at() and this works.
       selected-at(${catch_specie},position(..)-1)

For the label I use choice-name():
        jr:choice-name(selected-at(${catch_specie},position(..)-1), '${catch_specie}')
This gives a blank result.
It does work correctly when my multi-select options are listed under the 
choices tab (I use XLSForm), instead of being loaded from .csv file.

Files showing both are attached.

Does anyone know why this is happening? Is it a bug, or expected behaviour?

I would appreciate any suggestions for a workaround.

Thanks!
Andrew

Original issue reported on code.google.com by mitchellsundt@gmail.com on 29 Jun 2015 at 7:33

Attachments:

GoogleCodeExporter commented 8 years ago
Workaround info From Andrew:

Thanks Mitch, noted.

For anyone else bumping into this, the workaround I've used is to make use of 
pulldata() to get the value from the same file as the search():

calculate  sel_field              selected-at(${catch_specie},position(..)-1)
calculate sel_label              
pulldata('Species_Wcoast','name_Eng','name_key',${sel_field})

A further workaround is needed if you are dealing with multiple languages:

1) First you need to determine the language in use by the form. This is not 
accessible within a variable, so you need to calculate it.
For this you look at the selected value of a multichoice question (select_one 
or select_multiple) which does NOT load its options from a csv file, so that 
you can still use jr:choice-name() .This can be used to test which language 
label was displayed for the choice.
In my case I used a yes/no question - in English the labels are "Yes" and "No", 
in Afrikaans "Ja" and "Nee".  So if "Yes" or "No" was selected, then I know the 
form is being displayed in English, and I must pulldata() from the English 
label column

calculate    yesno_label          jr:choice-name(selected-at(${permit},0), 
'${permit}')
calculate    form_language      if(${yesno_label}='Yes' or ${yesno_label}='No' 
,'English','Afrikaans')

2) Second, you use the same pull_data as above, but select the correct language 
label column depending on the calculated language:

calculate  sel_field              selected-at(${catch_specie},position(..)-1)
calculate sel_label              if(${form_language}='English', 
pulldata('Species_Wcoast','name_Eng','name_key',${sel_field}), 
pulldata('Species_Wcoast','name_Afr','name_key',${sel_field}))

Hope that helps someone else!

Regards,
Andrew

Original comment by mitchellsundt@gmail.com on 30 Jun 2015 at 4:53