How do you dynamically set the default value for a text field?
I'm rating an object and when I rate the object as a problem I use a select_one to give me a list of short descriptions for the problem but I'd like to have a long description (like a pre-canned comment) text filed set based on which short description previously selected.
I tried using a relevant test to set the value. This works but only for a single selection. Enketo give me an error saying
There are more than one survey elements named 'ceiling_defect_long_descrip' (case-insensitive) in the section named 'ceiling_defect'.
Here's a section of the xlsform. The problem is enketo doesn't like the re-use of the nameceiling_defect_long_descrip even though it should only be selected once (no duplicates) based on the relevant test.
type name label required required_message hint calculation relevant appearance default
select_one obj_rating ceiling_rating Ceiling Rating
begin repeat ceiling_defect Bedroom Ceiling Defect(s) ${ceiling_rating} = 'repair_replace'
select_one ceiling_defect or_other ceiling_defect_descrip Bedroom Ceiling Defect ${ceiling_rating} = 'repair_replace'
image ceiling_defect_img Picture of problem ${ceiling_rating} = 'repair_replace' annotate
text ceiling_defect_long_descrip Long description of problem ${ceiling_defect_descrip} = 'ceiling_water_stains' multiline Here is default text 1
text ceiling_defect_long_descrip Long description of problem ${ceiling_defect_descrip} = 'ceiling_water_stains_moisture' multiline Here is default text 2
end repeat
end group
To get support in this forum, it is recommended to make it as easy as possible for others to reproduce your issue. So I recommend you take the time to create a simplified XLSForm file.
It looks like you have 2 questions with the same name ceiling_defect_long_descrip. That should not be allowed in XLSForm, so what puzzles me is that you are able to run this form in Enketo at all.
If you're comfortable with XML and XPath, and need more versatile query power you could also use xml-external: https://xlsform.org/en/#external-xml-data with an external XML file that contains your strings.
Thanks. Now, I understand what you were thinking, but that's not the way relevant works in our tools. Have a look at the XForm to see it produces two form controls and two model nodes.
I am still puzzled how you were able to create (convert) such a form and run it on Enketo. When trying myself to convert such a form on http://opendatakit.org/xlsform/ this is not possible. The error message show by the XLSForm converter is exactly what you are reporting though. So I think the error is shown by XLSForm Online (and not by Enketo). I am mentioning just in case we need to report a bug for the XLSForm converter.