aspnetcore-402244-rich-edit-fields.md
A field is a special placeholder for non-static data that can change, for instance, a page number or date and time.
A field is implemented as the Field client object. Use the SubDocument.fields property to access a collection of a sub-document’s fields. The RichEditDocumentBase.fields property returns a collection of the main sub-document‘s fields.
richEdit.selection.activeSubDocument.fields; // gets the active sub-document's fields
richEdit.document.fields; // gets the main sub-document's fields
Refer to the following section for examples: Field Examples.
A field has the {Code}Result> structure in the text buffer, for instance, {DATE}11/2/2020>.
The Code specifies how the Result should be calculated when the field is updated. In a document, a field can be displayed as a field code or field result.
You can get text buffer intervals that contain a field code (codeInterval), a field result (resultInterval), and an entire field (interval). To get the sub-document’s text buffer, call the getText method.
var field = richEdit.selection.activeSubDocument.fields.create(richEdit.selection.active, 'DATE');
richEdit.document.getText(field.interval); // returns "{DATE}>"
field.update(); // calculates the field result
richEdit.document.getText(field.interval); // returns "{DATE}11/2/2020>"
richEdit.document.getText(field.codeInterval); // returns "DATE"
richEdit.document.getText(field.resultInterval); // returns "11/2/2020"
The Code part of a field has the following syntax.
FIELDNAME Properties Optional_Switches
Refer to the following section for a list of supported field codes and their structures: Supported Fields.
You can insert a field into a document in the following ways (the examples below demonstrate how to insert the DATE field):
Call the create(position) method.
Call the executeCommand(commandId) method.
Select a ribbon command, for instance, Mail Merge → Create Field → DATE.
Use a shortcut, for instance, ALT + SHIFT + D.
Press CTRL + F9 to insert an empty field and add the field code.
Refer to the following section for instructions on how to insert a particular field into a document: Supported Fields.
Update a field to calculate and display the field result. You can use API members or the UI to update a field.
Call the executeCommand(commandId) method with the UpdateAllFields command as a parameter.
Call the updateAllFields method.
Select the Mail Merge → Update All Fields ribbon command.
false.Select a range that contains fields and do one of the following:
Call the executeCommand(commandId) method with the UpdateField command as a parameter.
Right click the selection, and select the Update Field context menu command.
Press F9.
Call a field’s update method.
Right click a field and select the Update Field context menu command.
Select a field and press F9.
Call the executeCommand(commandId) method with the UpdateTableOfContents command as a parameter.
Select the References → Update Table ribbon command.
The Rich Text Editor can display a field as a code (for instance, { DATE } ) or result (for instance, 11/2/2020 ). You can use API members or the UI to switch between modes.
Call the executeCommand(commandId) method with the ShowAllFieldCodes or ShowAllFieldResults command as a parameter.
Call the showAllFieldCodes or showAllFieldResults method.
Select the Mail Merge → Show All Field Codes or Show All Field Results ribbon command.
Press ALT + F9.
false.Set a field’s isShowCode property.
Right click a field and select the Toggle Field Codes context menu command.