Span
Span objects represent formatted text segments within rich text fields. They contain style and formatting information for portions of text in rich text form fields. Span objects are used with the richValue property of text fields that have richText enabled.
Example
var field = this.getField("richTextField")
field.richText = true
var spans = [
{text: "Bold text", fontWeight: 700},
{text: " and ", fontWeight: 400},
{text: "italic text", fontStyle: "italic"}
]
field.richValue = spans
Properties
alignment
| Secure | Type | Access |
|---|---|---|
| No | string | R/W |
The horizontal alignment of the text within the span.
Valid values:
-
"left"
-
"center"
-
"right"
Example
var span = {
text: "Centered text",
alignment: "center"
}
fontFamily
| Secure | Type | Access |
|---|---|---|
| No | string | R/W |
An array containing the font family name(s) for the span. The first element is the primary font family. Additional elements can specify fallback fonts.
Default value is ["sans-serif"].
Example
var span = {
text: "Custom font text",
fontFamily: ["Helvetica", "Arial", "sans-serif"]
}
fontStretch
| Secure | Type | Access |
|---|---|---|
| No | string | R/W |
The font stretch value for the span text.
Valid values:
-
"ultra-condensed"
-
"extra-condensed"
-
"condensed"
-
"semi-condensed"
-
"normal" (default)
-
"semi-expanded"
-
"expanded"
-
"extra-expanded"
-
"ultra-expanded"
Example
var span = {
text: "Condensed text",
fontStretch: "condensed"
}
fontStyle
| Secure | Type | Access |
|---|---|---|
| No | string | R/W |
The font style for the span text.
Valid values:
-
"normal" (default)
-
"italic"
Example
var span = {
text: "Italic text",
fontStyle: "italic"
}
fontWeight
| Secure | Type | Access |
|---|---|---|
| No | number | R/W |
The font weight for the span text. Values greater than 400 are considered bold.
Common values:
-
400 - Normal (default)
-
700 - Bold
Example
var span = {
text: "Bold text",
fontWeight: 700
}
strikethrough
| Secure | Type | Access |
|---|---|---|
| No | boolean | R/W |
When true, the text has a line through it. Default is false.
Example
var span = {
text: "Strikethrough text",
strikethrough: true
}
subscript
| Secure | Type | Access |
|---|---|---|
| No | boolean | R/W |
When true, the text appears as subscript. Default is false. Cannot be true if superscript is true.
Example
var span = {
text: "2",
subscript: true
}
// Creates H2O when combined with other spans
superscript
| Secure | Type | Access |
|---|---|---|
| No | boolean | R/W |
When true, the text appears as superscript. Default is false. Cannot be true if subscript is true.
Example
var span = {
text: "2",
superscript: true
}
// Creates x² when combined with other spans
text
| Secure | Type | Access |
|---|---|---|
| No | string | R/W |
The actual text content of the span.
Example
var span = {
text: "This is the text content"
}
textColor
| Secure | Type | Access |
|---|---|---|
| No | object | R/W |
The color of the text. Value is a color array in the same format as the color object. Default is black.
Example
var span = {
text: "Red text",
textColor: color.red
}
// Or using RGB array
var span = {
text: "Blue text",
textColor: ["RGB", 0, 0, 1]
}
textSize
| Secure | Type | Access |
|---|---|---|
| No | number | R/W |
The font size of the text in points. Default is 12.
Example
var span = {
text: "Large text",
textSize: 18
}
underline
| Secure | Type | Access |
|---|---|---|
| No | boolean | R/W |
When true, the text is underlined. Default is false.
Example
var span = {
text: "Underlined text",
underline: true
}
Usage examples
var field = this.getField("richTextField")
field.richText = true
// Create formatted text with multiple styles
field.richValue = [
{
text: "Important: ",
fontWeight: 700,
textColor: color.red,
textSize: 14
},
{
text: "This document expires on ",
fontWeight: 400,
textSize: 12
},
{
text: "December 31, 2024",
fontWeight: 700,
underline: true,
textSize: 12
}
]
var field = this.getField("formulaField")
field.richText = true
field.richValue = [
{text: "H", textSize: 12},
{text: "2", subscript: true, textSize: 12},
{text: "SO", textSize: 12},
{text: "4", subscript: true, textSize: 12}
]
var field = this.getField("mathField")
field.richText = true
field.richValue = [
{text: "E = mc", textSize: 12},
{text: "2", superscript: true, textSize: 12}
]
Resources
Revu 21
Revu JavaScript
JavaScript