Adding spaces between multiple case properties displayed in a single label question

Hello,
I'm having issues adding spaces between multiple case properties that I'm displaying in a label question. Do you have suggestions on how I can add spaces? The current view of the issue is in the following image where all the case properties are smooshed together.

And here's the hidden variable and case property I'm using:
who_did_you_contact

concat(if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'primary_caregiver'), #case/primary_caregiver_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'secondary_caregiver'), #case/secondary_caregiver_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'local_leader'), #case/local_leader_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'other') and #form/Abuse_Prevention_and_Care/caregiver_contact/if_other_who_did_you_attempt_to_contact != '', #form/Abuse_Prevention_and_Care/caregiver_contact/other_contact_names, ''))

Thank you for your support!
Julia

Here's the question that ties to the who_did_you_contact hidden variable/case property :
image

I think the easiest option might be to use the join() function, which will let you choose what should separate multiple arguments.

You can either use a space character( ' ' ) or you could even put together a bulleted list with newlines (I think the following is the correct syntax for that, but I might be wrong) ('\r* ').

Thank you, Clayton!

Based on the case property logic that I provided for who_did_you_contact, how would I use the join() function? I haven't used this before so figured I'd ask for some tips!

Best,
Julia

I think it's just changing concat to join, so something like

join(' ', if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'primary_caregiver'), #case/primary_caregiver_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'secondary_caregiver'), #case/secondary_caregiver_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'local_leader'), #case/local_leader_name, ''), if(selected(#form/Abuse_Prevention_and_Care/caregiver_contact/who_was_contacted, 'other') and #form/Abuse_Prevention_and_Care/caregiver_contact/if_other_who_did_you_attempt_to_contact != '', #form/Abuse_Prevention_and_Care/caregiver_contact/other_contact_names, ''))

Thanks, Clayton!

I adjusted the logic as you suggested but when I tested the logic, the names are still appearing in a confusing way. Do you have recommendations on how to add a bullet for each answer in the logic?

image.png

Thank you so much!
Julia

Hi Julia,

Personally I'd try replacing the join separator (' ') with a newline and a bullet and trying to make a bulleted list. ('\r* ', I think)

Thank you again, Clayton!

Looks like I might be coding incorrectly (thanks for bearing with me - I'm fairly new to coding in CommCare). Could you steer me in the right direction?

I got a chance to play around with this, and it looks like I was wrong about being able to use the /r for newlines.

I did manage to get it to work. It seems like the easiest way to encode a newline is actually just to physically insert it with the advanced editor. The form builder retains the newline as part of the expression itself.

Here's a screenshot of the test I did, I hope that helps. Note: I also realized that you need a leading bullet for markdown to recognize it as a list. I added that with "concat" so it would all be on one expression, but if you have a bullet in the actual label instead it should work the same way.

Thanks Clayton - this is really helpful!
I added this logic to the CommCare and noticed bullets were showing for all options even though they should only appear if that option was selected. Any tips on how to remove bullets unless an answer is selected?

image.png

Best,
Julia

Ah, right, I suppose that makes sense.

It's more verbose, but I guess you'd just need to define it manually by only adding the newlines and bullet points individually inside of the if() statements with concat rather than being able to use the join() syntax.