cut

RichEditCommands.createField Property

Gets a command to add a field at the current position in a document.

Declaration

readonly createField: CreateFieldCommand

Property Value

Type Description
CreateFieldCommand

An object that provides methods that execute the command and check its state.

Remarks

Call the execute method to invoke the command. The method checks the command state (obtained via the getState method) to determine whether the action can be performed.

You can execute the command without parameters or with an optional code parameter depending on your requirements:

  • The command without parameters creates an empty field and populates it with characters in the selected range if there are any;
  • The command with the code parameter creates and updates a field containing text received from the parameter.

Usage examples:


//example 1
richEdit.commands.createField.execute();

//example 2
richEdit.commands.createField.execute("TOC \\h \\c \"Figure\"");

//example 3
richEdit.commands.createField.execute();
richEdit.commands.insertText.execute("Date");
richEdit.commands.updateField.execute();

//example 4
var fieldCode = "Date";
richEdit.commands.insertText.execute(fieldCode);
richEdit.selection.intervals = [new ASPx.Interval(rich.selection.intervals[0].start - fieldCode.length, fieldCode.length)];
richEdit.commands.createField.execute();
richEdit.commands.updateField.execute();
See Also