We are working on contact forms to make certain changes in the household interface. We are creating a field in the ‘c80_household-create’ form where we can select street name. Each street name is assigned with their street code as a variable, such that those variable can later be concatenated with house number and place code to form a house ID. However, there are some cases where two different streets hold same street code.
We made use of ‘allow_choice_duplicates’ and tested in the enketo where it is working well. But after uploading the form in the CHT, two of the choices with same street codes are displayed together.
For example:
Here Raiti Marg and Rajkul-tripurasundari marg are two different streets with same street codes, but they are merged together as “Raiti MargRajkul-tripurasundari marg” on both the options while being displayed in the form.
Hi @gaarimasharma, thank you for sharing the problem here, and thanks to @sanjay for tagging me.
I was able to reproduce the problem somewhat, but for me the options displayed were slightly different from yours.
choices:
list_name
name
label
streets
1
Street 1
streets
2
Street 2a
streets
2
Street 2b
streets
3
Street 3
survey:
type
name
label
appearance
calculation
select_one streets
street
Street
minimal
On CHT 3.16.0, it looks like this:
Please note that the option Street 2a is not displayed above. I am curious to know more about your form configuration and setup as your have both options displayed.
However, we can agree that there is a problem and it looks like setting allow_choice_duplicates has no effect. While we can investigate further how we can support it in the future, let me suggest a workaround for now:
choices:
list_name
name
label
streets
1_a
Street 1
streets
2_a
Street 2a
streets
2_b
Street 2b
streets
3_a
Street 3
survey:
type
name
label
appearance
calculation
select_one streets
street_select
Street
minimal
calculate
street
substring-before(${street_select}, '_')
Here we are creating a calculate field street to convert 1_a, 2_a, 2_b etc. to 1, 2, 2 respectively. We can use this field to generate the house ID.
I tested this this with the new Enketo version coming in CHT 4.0.0 and the display is a bit different (there are still 2 entries with the same label, though).
The main challenge here is that the the xform logic relies on the choice name as the key for referencing the choice label translation(s) in the generated xml file. So, having two choices with the same name is always going to cause label collisions like this (where only one of the labels is actually stored in the xml file). So, some kind of work-around like what @binod has suggested is going to be required.
(Also worth noting that from what I have read the allow_choice_duplicates setting does not affect the content of the generated xml, but instead is just used for suppressing the dup error that comes in later versions of pyxfom. I do not think it has any affect at all when using the current version of pyxform-medic.)
One alternative workaround that comes to mind is that you could use a separate column on the choices sheet to store the street data for each select entry and then extract that data into a calculate:
@binod sir Thank you for your response.
This is how my form looks;
survey:
type
name
label
appearance
select_one streets
street_name
Street Name
minimal
choices:
list_name
name
label
streets
DL2055
Timmure besi goreto bato
streets
DL2056
Raiti Marg
streets
DL2056
Rajkul - tripurasundari marg
streets
DL2056G
Wochita marg
I have used the same format in the form as yours above. However, I uploaded the form in CHT 3.15.0 if that could be the possible reason for the difference.