Set default text field from lookup

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'.

Hi @WAVE,

Welcome to the community! Could you please share a form that shows how far you got? (the simpler the form the better).

Here's a section of the xlsform. The problem is enketo doesn't like the re-use of the name ceiling_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

Hi @WAVE,

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.

Enketo will not run the form due to the same name, that's what I'm trying to figure out.

I have a relevant test which at run time should produce only a single instance of ceiling_defect_long_descrip.

Is there another way to accomplish this?

`

If you only have a few strings I would use an if() statement.

If you have more than 2 or 3 strings, you could consider using a CSV file and the pulldata() function: https://xlsform.org/en/#how-to-pull-data-from-csv.

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.