Skip to main content
MamaDesignKitty
New Participant
July 31, 2022
Answered

Formatting text field line spacing in JS

  • July 31, 2022
  • 4 replies
  • 3021 views

Is it possible to set line spacing for a text field / variable?

 

var strWord1 = this.getField("CityName").valueAsString;
event.value = strWord1 +" is hosting an event..."

 

I've seen that it can't be done within Form Edit mode. Is it possible with JS?

Thanks!

This topic has been closed for replies.
Correct answer MamaDesignKitty

Ok, so I actually kept looking and I found this amazing custom keystroke script that worked great!

 

var spans = event.richValue;
if (spans !== undefined && event.willCommit) {
for ( var i = 0; i < spans.length; i++ ) {
spans[i].textSize = 10; // font size
spans[i].linespacing = 15; // linespacing

// restore line breaks
if (spans[i].endParagraph) spans[i].text += "\r";

// reset styles to default
spans[i].fontStyle = "normal";
spans[i].fontWeight = 400;
spans[i].strikethrough = false;
spans[i].underline = false;
spans[i].textColor = color.black;
spans[i].alignment = "left";
spans[i].fontFamily = ["Arial"];
}

event.richValue = spans;
}

 

Thanks also to Alex at https://stackoverflow.com/questions/25380882/linespacing-in-multiline-fields

 

4 replies

New Participant
May 10, 2024

Hi, I'm having this same issue, but the keystroke script is not working.  I think it's because I don't have an person typing in the form, but rather the data is being mapped to fields from smartsheet.  Is there a script that would work in the Format section instead of the Keystroke section? 

 

MamaDesignKitty
MamaDesignKittyAuthorCorrect answer
New Participant
August 2, 2022

Ok, so I actually kept looking and I found this amazing custom keystroke script that worked great!

 

var spans = event.richValue;
if (spans !== undefined && event.willCommit) {
for ( var i = 0; i < spans.length; i++ ) {
spans[i].textSize = 10; // font size
spans[i].linespacing = 15; // linespacing

// restore line breaks
if (spans[i].endParagraph) spans[i].text += "\r";

// reset styles to default
spans[i].fontStyle = "normal";
spans[i].fontWeight = 400;
spans[i].strikethrough = false;
spans[i].underline = false;
spans[i].textColor = color.black;
spans[i].alignment = "left";
spans[i].fontFamily = ["Arial"];
}

event.richValue = spans;
}

 

Thanks also to Alex at https://stackoverflow.com/questions/25380882/linespacing-in-multiline-fields

 

bebarth
Community Expert
August 1, 2022

Hi,

Given the try67's answer I'm not sure to correctly understand the question, but it is possible to set the line spacing of a text field set in rich text! See the attached file...

@+

try67
Community Expert
August 1, 2022

I stand corrected! However, this is an undocumented property, so use it at your own risk... It does work nicely, though.

try67
Community Expert
July 31, 2022

Not possible with a script.