Starting with version 3.1, you can dynamically change the label of a question, using answers from other questions in the form. Dynamic question labels are particularly handy when working with very long forms, making questions in your survey more meaningful to end-users.
The Water Violation survey sample on the side, for example, shows how you can insert the Type of Violation and Name of Offender in the photo and signature questions that follow.
This is quite a simple example to illustrate the idea. As your survey includes questions across multiple groups, repeats and even pages, dynamic labels become critical to aid with form navigation and to avoid user input errors.
The dynamic labels technique is often described in survey jargon as question piping, where user responses are inserted or piped into questions further into the survey.
You can add dynamic labels to your forms using Survey123 Connect for ArcGIS. Once published, dynamic labels will work in both the Survey123 web as well as the field apps.
The basics of dynamic labels in XLSForm
In order to insert text dynamically within a question label, you must add XLSForm variables in the label column of your survey. The syntax is quite simple. Insert ${QuestionName} exactly where you want the answer to a particular question in the survey to appear in your label. This is what the Water Violation example illustrated above looks like in XLSForm.
You can add multiple variables to the same label but it is important to highlight that the use of full XLSForm expressions within the label column is not supported. Survey123 will only replace XLSForm variables. For example, this is valid:
But this is not valid:
While you cannot use full XLSForm expressions within the label, you can use them in a calculate question, and then reference your calculate question in the label. Calculate questions will not show in your form, but will help you hold the output of full XLSForm expressions, so you can insert those values in a label. For example, lets pretend you want to use a dynamic label in a note to describe the total cost of repairs of a pipe, given its length:
The cost question is a calculate. It will not be shown in the form to the end-user. We use the cost calculate question to run a full expression that evaluates the total cost, and once we have that, we simply use it for our dynamic label.
Working with different data types
As you work with dynamic labels, you will notice that things are straight-forward when you want to insert values from questions of type text, decimal or integer. All you will need to do is to reference these questions directly exactly as shown above. When working with other types such as dates or select questions, things are a bit more complicated and you will need to pre-process user values through calculate questions before you insert them into the label.
Support for the XLSForm jr:choice-name() function was introduced in Survey123 in version 3.1 in both the field and web Survey123 apps. This function takes two inputs: a string representing a choice name, and a second string representing the name of the select question. Note that the second parameter requires you to enclose the question with quotes.
The output of this function is the label of the choice name passed-in. If this function is used in a multi-language survey, the label returned is that of the active language.
Other things to consider
There are some obvious and not so obvious things to consider when working with dynamic labels:
When you publish an XLSForm document with Survey123 Connect, we take the values in the name column of your survey spreadsheet and we use them to create new fields in the survey feature layer. By default, we use the contents of the label XLSForm column to define the field aliases of your attribute fields. Typically, ArcGIS apps will use the field alias for display purposes. This is the case in the popup of a web map as well as throughout the Survey123 website.
When you insert a dynamic label, your field aliases will include the variable placeholder and that will not look very nice. If you are worried about this, make sure you set the alias value for your attribute fields in the esri::bind:esriFieldAlias XLSForm column. Alternatively, you can also refine the field aliases, after the survey is published, from the Item Details page of the feature layer item.
If used wisely, dynamic labels can help you build better and more user friendly smart forms. We hope this new feature is useful to you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.