Line shift in field for comments?

656
3
Jump to solution
01-20-2023 02:33 AM
LarsElmkær_Chwastek
Occasional Contributor

Hi all, 

Do anyone know if it is possible to do any customization to a text field in a layer for instance in the Map Viewer in an Enterprise environment? 

What we have is a lot of "Comments" fields in layers, and a lot of them will actually contain a lot of information. But it is very difficult to read, because it is just in one long string... 

Is it for instance possible to do line shift in a text field? Through some Arcade? It could both be in the pop-up after you've entered it, but also in the text field itself, while you are entering information. Here it is also difficult to see where you are entering what, when there is too much text. 

So any suggestion to better view the text is appreciated 🙂 

Thanks

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Manual linebreaks

You can insert linebreaks into a text field by pressing Shift + Enter.

 

Automatic linebreaks

Using Arcade, you can automatically insert linebreaks. You can use these expressions in popups (somehow it does not work in the Pro popup...), in attribute rules, or in the field calculator.

Option 1: line break after certain symbols

var symbols = [".", ";"]
var t = $feature.TextField
for(var i in symbols) {
    var s = symbols[i]
    var lbs = s + "\n"
    t = Replace(t, lbs, s) // remove manual breaks to avoid empty lines
    t = Concatenate(Split(t, s), lbs)
}
return t

 

Option 2: line break after a certain length

var words = Split($feature.TextField, " ")
var max_length = 20
var t = ""
var l = 0
for(var i in words) {
    var word = words[i] + " "
    l += Count(word)
    if(l <= max_length) {
        t += word
    } else {
        t += TextFormatting.NewLine + word
        l = 0
    }
}
return t

 

Here's how the two options look in a MapViewer popup:

JohannesLindner_1-1674217588820.png

 

 


Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Frequent Contributor

Manual linebreaks

You can insert linebreaks into a text field by pressing Shift + Enter.

 

Automatic linebreaks

Using Arcade, you can automatically insert linebreaks. You can use these expressions in popups (somehow it does not work in the Pro popup...), in attribute rules, or in the field calculator.

Option 1: line break after certain symbols

var symbols = [".", ";"]
var t = $feature.TextField
for(var i in symbols) {
    var s = symbols[i]
    var lbs = s + "\n"
    t = Replace(t, lbs, s) // remove manual breaks to avoid empty lines
    t = Concatenate(Split(t, s), lbs)
}
return t

 

Option 2: line break after a certain length

var words = Split($feature.TextField, " ")
var max_length = 20
var t = ""
var l = 0
for(var i in words) {
    var word = words[i] + " "
    l += Count(word)
    if(l <= max_length) {
        t += word
    } else {
        t += TextFormatting.NewLine + word
        l = 0
    }
}
return t

 

Here's how the two options look in a MapViewer popup:

JohannesLindner_1-1674217588820.png

 

 


Have a great day!
Johannes
LarsElmkær_Chwastek
Occasional Contributor

Hi Johannes,

I'm using the arcade option 1 and when I click Test it looks perfect. However when I open my pop-up, the text field hasn't changed. It is as if the expression isn't being read... Is there a step I'm missing? I've only changed the name of the field and then clicked ok.

LarsElmkr_Chwastek_0-1674638722761.png

 

 

0 Kudos
LarsElmkær_Chwastek
Occasional Contributor

Hi Johannes,

Thnak you so much for your input - I will get straight on it, and might have some follow up 🙂

0 Kudos