Custom plugin to add inline form field with tag

Do you want to: Ask a how-to question

Document Server version: 8.1.3.4 / Docker

We are evaluating OnlyOffice to be the editor in our product. Our use case for OnlyOffice to use it to edit docx file and mark part of the words as form fields using custom plugin.

Plugin is using this code to add inline form field:

plugin.callCommand(() => {
          const oDocument = Api?.GetDocument();

          const formProps = {
            key: Asc.scope.clickedItem.id, // "company_name"
            tag: Asc.scope.clickedItem.id,// "company_name"
            tip: Asc.scope.clickedItem.text.en, // "Company name"
            required: true,
            placeholder: Asc.scope.clickedItem.text.en,
            comb: false,
            multiLine: true,
            autoFit: false,
          };
          oDocument.InsertTextForm(formProps);
}

And later using this method to list forms

this.executeMethod("GetAllForms", null, function (data) {
            data.forEach((form) => {
              console.log(form); // {Tag: '', Lock: 3, InternalId: '1950'}
            });
          });

For some reason tag isn’t attached to form at all, and for this, we can’t bind our plugins input fields to form field. What is correct way to add tag to form?

Hello @tuomasglad

Not quite understand why InsertTextForm is used in document editor when it is method for Forms editor. Instead of tags, these forms use key, please check out this sample of interaction with fields from outside the editor:

I have seen that example. In that example document already has form fields defined. I´m trying to define form fields using document editor and then fill them later.

Form fields have only InternalId defined when fetched with GetAllForms method. Tag and key are both empty.

I can define ContentFields and ContentFields preserves tags when accesses with GetAllContentFields. I can’t use Content fields because I couldn’t find a way to highlight them programmatically nor I couldn’t find a way to set values to them like in example you provided.