Autofill a text question (default) and have it not show up on the survey, but does fill in the export?

type name label required default
text city City false City_name

I am collecting data from cities and would like to have the city name already in the default, and hidden to the viewer of the survey. However when I export the file, the city name is blank, despite being in default. Is there any way to hide a question and autofill it?

Thanks

1 Like

In your XLSForm you can use a “hidden” question type, and fill in your desired value in its default.

This will basically pre-populate a text value in the form submission data (ie instance XML) which will be submitted along with all the other user entered data, but it does not appear as an actual question in the displayed form itself, hence the user has no ability to change it.

Caveat: I don’t think KoboToolbox KPI form builder exposes the ‘hidden’ question type (although if you manually put it in your XLSForm it’ll accommodate it). If you want to do this entirely using the Kobo form builder you can use a calculation control, and set its calculated value to your desired default, to achieve the same result.

2 Likes

What code can I use to put the “hidden” question type in and what column? Currently I am putting the desired answer in the default column. But it is showing in the survey, autofilled. Where can I hide the question?

1 Like

Take a look at this XLSForm to see how to implement either a ‘hidden’ control (unsupported by Kobo form builder) or an equivalent calculation control (supported):

hiddentest.xls (19 KB)

Note the show_calculation and show_hidden are just to show the respective form values do in fact exist in the submission data; they can be omitted.

1 Like

FYI, it looks like Kobo form builder doesn’t just not support ‘hidden’ controls, but it will throw an error if you try to load and edit an XLSForm containing them, and will then remove them should you subsequently try to export the form. I’ve open a github issue to track: https://github.com/kobotoolbox/kpi/issues/2239

Which is to say, although both Enketo and Collect (and KoboCollect) clients will in fact support deployed XML forms generated from XLSForms that contain ‘hidden’ controls, if you wish to edit any such XLSForms using the Kobo form builder they’ll get munted. So my recommendation for those using the Kobo form builder is to use the calculation approach.

1 Like

Hi ryon_1

I have different opinion
I think what you need is calculation
First, Please check out this link !
https://ee.kobotoolbox.org/x/#9LwLcngY

Please, find the attached file …
ryon_1.xls (22 KB)

Please, find the attached new file … [There are typos in file before]
ryon_22.xls (22 KB)

I create “calculate” question type, then i give calculation [example : “JAKARTA”],
It’s hidden, but when you export the submissons you have the data.

I create a note to view a calculation, please delete it. It’s just show you the calculation.

Regards
Tulus

Correct. Using a calculation is the alternative (which I included also). The end result is the same, however the nature of XForms is that, depending on the client, calculations may need to be re-executed when anything changes (although in Collect there is an optimization to avoid this by calculating a dependency tree beteeen all calculations, and only re-executing those dependent upon each change). And re-evaluating XPath calculations that always return a constant/literal is just wasted CPU cycles.

Sticking a default value in the form instance XML is still the most efficient, which is what XLSForms ‘hidden’ control does. But unfortunately it’s not supported in Kobo yet.

Hi, yes your right. No “hidden” type (different to XLSForms spec!) in KoBoCollect. Why? It gives an error (undefined type) on XLSForm import already.

Would be great to have a condensed list of what is different in KoBoCollect against the XLSForm spec. Any link for this?
Best regards