All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.

Field

  • 2 minutes to read

Get all fields in the main sub-document

Related members: fields

var mainSubDocumentFields = richEdit.document.fields;

Create a field at the cursor position

Related members: create(position), fields, Field, activeSubDocument, active, getText

var subDocument = richEdit.selection.activeSubDocument;
var field = subDocument.fields.create(richEdit.selection.active, 'time');
field.update(function(self) {
    console.log('Result: ' + subDocument.getText(self.resultInterval));
});

Delete a field but keep the field result

Related members: beginUpdate, beginTransaction, create(position), update, getText, deleteText(interval), insertText(position, text), endTransaction, endUpdate

var subDocument = richEdit.selection.activeSubDocument;
richEdit.beginUpdate();
richEdit.history.beginTransaction();
// creates and updates the 'time' field, and then calls the callback function
subDocument.fields.create(richEdit.selection.active, 'time').update(function(field) {
    var pos = field.interval.start;
    // gets the field result value
    var text = subDocument.getText(field.resultInterval);
    // deletes the field
    subDocument.deleteText(field.interval);
    // inserts the field result value
    subDocument.insertText(pos, text);
    richEdit.history.endTransaction();
    richEdit.endUpdate();
});

Remove a field

Related members: fields, delete

richEdit.document.fields.getByIndex(0).delete();

Update all fields

Related members: fields, updateAllFields, UpdateFieldsOptions

var doInAllSubDocuments = true;
var updateTocFields = true;
var options = new DevExpress.RichEdit.UpdateFieldsOptions(doInAllSubDocuments, updateTocFields);
richEdit.document.fields.updateAllFields(function() {
    console.log('Updated');
}, options);

Update all fields once the editor is shown

Related members: OnDocumentLoaded(String), fields, updateAllFields

@(Html.DevExpress().RichEdit("richEdit")
    .OnDocumentLoaded("function(s, e) { s.document.fields.updateAllFields(); }")
...

Update fields by name

Related members: fields, name, FieldName, update

rich.beginUpdate();
rich.history.beginTransaction();
for(var i = 0, field; field = rich.document.fields.getByIndex(i); i++)
    if (field.name == DevExpress.RichEdit.FieldName.FillIn)
        field.update();
rich.history.endTransaction();
rich.endUpdate();

Update all fields and highlight the result

Related members: beginUpdate, beginTransaction, updateAllFields, UpdateFieldsOptions, fields, setCharacterProperties(interval, characterProperties),

richEdit.history.beginTransaction();
richEdit.beginUpdate();
richEdit.document.fields.updateAllFields(function () {  
    richEdit.document.subDocuments.forEach(function (subDocument) {
        for (var i = 0, field; field = subDocument.fields.getByIndex(i); i++)
            richEdit.document.setCharacterProperties(field.resultInterval, { bold: true });
    });
    richEdit.endUpdate();
    richEdit.history.endTransaction();  
}, new DevExpress.RichEdit.UpdateFieldsOptions(true, false));