Why do we have to use replace to insert newlines in repeaters?

Why is it exactly that we have to insert a newline character into repeater text with the .replace(**delimiter**,"\n") function? Like in a technical sense, I’m just trying to understand it.

If I put “\n” inside the repeater text it doesn’t work. I thought I’d be clever and tried .replace("\n","\n") to no avail. What is it that magically makes “\n” turn into a newline but only when replaced?

Hi!

This is an interesting question! I tested out the scenario on my end as well and I see what you’re seeing regarding the newline character working as intended when swapped for a delimiter but not when swapping for “\n” in the dataset. I reached out to our team about this and it looks like there’s not a known technical reason why this doesn’t work in both cases, so it’s most likely a bug. I’ll get that filed on our end so that we can look deeper to see why sometimes “\n” triggers a new line and why sometimes it’s a string.

I’ll also go ahead and file a feature request for the newline character to work within repeater datasets so that the replace function isn’t necessary.

2 Likes

Hello @bamorris,

We had the opportunity to escalate this question to our engineering team, and have made some progress on the matter.

When we use .replace("\n","\n") in our Repeater widget, we’re actually replacing the existing \n with another \n. The reason that this doesn’t work is both instances of \n are being treated as a string. We can get around this by using the following syntax. Where the first \ (the delimiter) is being treated as the ‘escape’ character.
[[Item.First_Name.replace("\\n",'\n')]]

Further to the above, in Axure RP, when we use a function with a single quote ( ’ ), we are only targeting one character, whereas using double quotes ( " ) allows us to target more than one character in the function.

For example, using ‘#’ will only target the # symbol. But using “##” allows us to target both the ## symbols.

To summarize, we can use either of the following functions to escape the string in the repeater and create a new line.

Option 1: Targets the . symbol and replaces it with a new line.
[[Item.First_Name.replace('.','\n')]]

Option 2: Escapes the string using \ , targets the text with \n and replaces it with a new line function.
[[Item.First_Name.replace("\\n",'\n')]]

I hope this proves helpful, but we remain on hand for any queries.

James

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.