Preload with previous question values

Let’s say I want to preload a text question with a combination of the values from previous questions.

Should I use calculate() with concat()? Or is there an easier way?

In playing around using text from previous questions, I found that spaces between values won't be respected but if you have a hard-coded character it will allow enforcing a space. So if word_1=alpha, word_2=beta, and word_3=charlie.

  • lorem ${word_1}. ${word_2}. ${word_3}. ipsum
    will display as
    lorem alpha. beta. charlie. ipsum
  • but there is no difference between
    lorem ${word_1} ${word_2} ${word_3} ipsum
    lorem ${word_1}${word_2}${word_3} ipsum
    as both display as
    lorem alphabetacharlie ipsum
  • doing a calculate such as concat(${word_1}, " ",${word_2}," ",${word_3}) will allow you to insert the spaces between the values

So I think it depends on how you need to combine your values and your hard coded text.
${last_name}, ${first_name} should be fine without a calculate and concat() but if you want ${first_name} ${last_name} with the space you will need the concat().

@danbjoseph super helpful, thank you!

Just so I'm clear, in the case where I don't need calculate, would I put the value to be preloaded ($ exprs and all) directly into the instance or is there some other bind attribute I should use?

Also if anyone knows where the $ stuff is documented, holler please. I had a look through but couldn't find it.

Apologies, my response was based on authoring a survey using XLSForm but I downloaded the survey as an XForm and this question:

| type |  name   |                    label                     |
| note | my_note | lorem ${word_1}. ${word_2}. ${word_3}. ipsum |

is turned into:

<input ref="/dataInNotes/my_note">
<label>lorem <output value=" /dataInNotes/data_input/word_1 "/>. <output value=" /dataInNotes/data_input/word_2 "/>. <output value=" /dataInNotes/data_input/word_3 "/>. ipsum</label>

(where dataInNotes is the survey form name)

Does that help?

1 Like

See also this survey and using-responses.xml (2.3 KB)

|    type     |    name     |                label                 | appearance |                      calculation                       |
| begin group | name        |                                      | field-list |                                                        |
| text        | last        | Last name                            |            |                                                        |
| text        | first       | First name                           |            |                                                        |
| end group   |             |                                      |            |                                                        |
| integer     | age         | Age (years)                          |            |                                                        |
| calculate   | concat_data |                                      |            | concat(${first}," ",${last}," (",${age}," years old)") |
| note        | note        | ${last}, ${first} (${age} years old) |            |                                                        |
| note        | note_concat | ${concat_data}                       |            |                                                        |
1 Like

Thank you again. This is immensely helpful!