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 | array | 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 H₂O 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
Creating rich text with multiple spans
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
}
]
Chemical formula with subscripts
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}
]
Mathematical expression with superscripts
var field = this.getField("mathField")
field.richText = true
field.richValue = [
{text: "E = mc", textSize: 12},
{text: "2", superscript: true, textSize: 12}
]