Skip to main content
MamaDesignKitty
Participant
Jul 31, 2022 6:59 PM UTC
Answered

Formatting text field line spacing in JS

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 is closed to new replies. Start a new post to keep the conversation going.
MamaDesignKitty
MamaDesignKittyCorrect answer
Participant
Aug 2, 2022 2:35 AM UTC

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

 

6 replies

Participant
May 10, 2024 5:48 PM UTC

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? 

 

Translate
MamaDesignKitty
MamaDesignKittyAuthorCorrect answer
Participant
Aug 2, 2022 2:35 AM UTC

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

 

Translate
bebarth
Community Expert
Community Expert
Aug 1, 2022 4:28 PM UTC

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...

@+

Translate
try67
Community Expert
Community Expert
Aug 1, 2022 7:52 PM UTC

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

Translate
try67
Community Expert
Community Expert
Jul 31, 2022 7:50 PM UTC

Not possible with a script.

Translate