Field Class
Defines a field in the document.
Declaration
export class Field
Remarks
Fields are special placeholders for non-static data that might change (for instance, page numbers, actual dates and times).
A field is specified by a field code, and can be viewed within a document as either a field code or a field result. The field code specifies how the field result should be calculated when the field is updated.
A field has the following structure in the text buffer: {Code}Result>; for instance, {DATE}09-Oct-18>.
Supported field code names
Code Name | Description |
---|---|
DATE | Inserts the current date and time. |
DOCVARIABLE | Enables you to programmatically insert complex content when the field is updated. |
HYPERLINK | Enables you to navigate to another location or to a bookmark. |
MERGEFIELD | Retrieves a value from the bound data source. |
NUMPAGES | Inserts the total number of pages. |
PAGE | Inserts the number of the page containing the field. |
TIME | Inserts the current time. |
TOC | Inserts the table of contents. |
SEQ | Inserts the number of the figure/table/equations. |
TC | Inserts the alternate entry for the table of contents. |
PAGEREF | Inserts a number of the page that stores the specified bookmark for a cross-reference. |
Inheritance
Properties
codeInterval Property
Gets the text buffer interval that contains the field’s code.
Declaration
readonly codeInterval: Interval
Property Value
Type | Description |
---|---|
Interval | The text buffer interval. |
Remarks
A field has the following structure in the text buffer: {Code}Result>; for instance, {DATE @ “M/d/yyyy”}6/20/2019>.
Use the codeInterval property to get the text buffer interval that contains the field’s code.
// returns "{DATE \@ "M/d/yyyy"}6/20/2019>"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).interval);
// returns "DATE \@ "M/d/yyyy""
richEdit.document.getText(richEdit.document.fields.getByIndex(0).codeInterval);
// returns "6/20/2019"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).resultInterval);
index Property
Gets the field’s index in a field collection.
Declaration
readonly index: number
Property Value
Type | Description |
---|---|
number | A zero-based index. |
Remarks
You can use the getByIndex(index) method to find a field by its index in the FieldCollection object.
richEdit.document.getText(richEdit.document.fields.getByIndex(0).resultInterval);
interval Property
Gets the text buffer interval that contains the field.
Declaration
readonly interval: Interval
Property Value
Type | Description |
---|---|
Interval | The text buffer interval. |
Remarks
A field has the following structure in the text buffer: {Code}Result>; for instance, {DATE @ “M/d/yyyy”}6/20/2019>.
Use the interval property to get the text buffer interval that contains the entire field.
// returns "{DATE \@ "M/d/yyyy"}6/20/2019>"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).interval);
// returns "DATE \@ "M/d/yyyy""
richEdit.document.getText(richEdit.document.fields.getByIndex(0).codeInterval);
// returns "6/20/2019"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).resultInterval);
isHyperlink Property
Returns whether the field is a hyperlink.
Declaration
readonly isHyperlink: boolean
Property Value
Type | Description |
---|---|
boolean | true, if the field is a hyperlink; otherwise; false. |
isShowCode Property
Specifies whether the field’s code or result is visible.
Declaration
isShowCode: boolean
Property Value
Type | Description |
---|---|
boolean | true, if the field code is visible; false, if the field result is visible. |
resultInterval Property
Gets the text buffer interval that contains the field’s result.
Declaration
readonly resultInterval: Interval
Property Value
Type | Description |
---|---|
Interval | The text buffer interval. |
Remarks
A field has the following structure in the text buffer: {Code}Result>; for instance, {DATE @ “M/d/yyyy”}6/20/2019>.
Use the resultInterval property to get the text buffer interval that contains the field’s result.
// returns "{DATE \@ "M/d/yyyy"}6/20/2019>"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).interval);
// returns "DATE \@ "M/d/yyyy""
richEdit.document.getText(richEdit.document.fields.getByIndex(0).codeInterval);
// returns "6/20/2019"
richEdit.document.getText(richEdit.document.fields.getByIndex(0).resultInterval);
Methods
delete Method
Deletes the current field.
Declaration
delete(): void
Remarks
richEdit.document.fields.getByIndex(1).delete();
update Method
Updates and displays the field’s result.
Declaration
update(
callback?: (self: Field) => void
): boolean
Parameters
Name | Type | Description |
---|---|---|
callback | (self: Field) => void | A function that is called after the field is updated. |
Returns
Type | Description |
---|---|
boolean | true, if the field has been updated successfully; otherwise, false. |
Remarks
richEdit.document.fields.getByIndex(1).update();
To update all field results, use the updateAllFields method.
richEdit.document.fields.updateAllFields();