# docx-editor-form-fields

> Word editor loads a form-fields document with fillable form content and spinner loading.

**Framework:** vue  **Component:** DocxEditor  **Variant:** form-fields

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/vue/docx-editor-form-fields.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-buttons @syncfusion/ej2-vue-documenteditor @syncfusion/ej2-vue-popups @syncfusion/ej2-vue-splitbuttons
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/docx-editor-form-fields/DocxEditor.vue

```vue
<template>
    <div class="control-section">
  
    <div class="sample-container">
        <div class="default-section">
            <div ref="de_titlebar" id="documenteditor_titlebar" class="e-de-ctn-title">
                <div v-on:keydown="titleBarKeydownEvent" v-on:click="titleBarClickEvent" class="single-line" id="documenteditor_title_contentEditor" title="Document Name. Click or tap to rename this document." contenteditable="false">
                    <label v-on:blur="titleBarBlurEvent" id="documenteditor_title_name" :style="titileStyle" >{{documentName}}</label>
                </div>    
                <ejs-button ref="de-print" id="de-print" :style="iconStyle" :iconCss="printIconCss" v-on:click="printBtnClick" title="Print this document (Ctrl+P).">Print</ejs-button>	
                <ejs-dropdownbutton ref="de-export" :style="iconStyle" :items="exportItems" :iconCss="exportIconCss" cssClass="e-caret-hide" content="Download" v-bind:select="onExport" :open="openExportDropDown" title="Download this document."></ejs-dropdownbutton>        
            </div>
            <div style="display:block; height: calc(100vh - 230px);">
            <ejs-documenteditorcontainer ref="doceditcontainer" :toolbarMode="'Ribbon'" :serviceUrl="hostUrl" :documentEditorSettings="settings" :enableToolbar='true' :fileMenuItems="fileMenuItems" :fileMenuItemClick="fileMenuItemClick" height='100%'></ejs-documenteditorcontainer>
            </div>
        </div>
    </div>
</div>
</template>
<style>
#documenteditor_titlebar {
    height: 36px;
    line-height: 26px;
    width: 100%;
    font-size: 12px;
    padding-left: 15px;
    padding-right: 10px;
    font-family: inherit;
}

#documenteditor_title_contentEditor {
    height: 26px;
    max-width: 85%;
    width: auto;
    overflow: hidden;
    display: inline-block;
    padding-left: 4px;
    padding-right: 4px;
    margin: 5px;
}

[contenteditable="true"].single-line {
    white-space: nowrap;
    border-color: #e4e4e4 !important;
}

[class^="e-de-icon-"],
[class*=" e-de-icon-"] {
    font-family: 'Sample brower icons' !important;
}

.e-de-icon-Print:before {
    content: "\e723";
}

.e-de-icon-Download:before {
    content: "\e728";
}

</style>
<script>
import { DocumentEditorContainerComponent,Toolbar, Ribbon } from "@syncfusion/ej2-vue-documenteditor";
import { DropDownButtonComponent } from "@syncfusion/ej2-vue-splitbuttons";
import { createSpinner, showSpinner, hideSpinner } from "@syncfusion/ej2-vue-popups";
import { formfields } from "../datasource/docx-editor-data";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
import "../style.css";

export default {
    components: {
        'ejs-documenteditorcontainer': DocumentEditorContainerComponent,
        'ejs-dropdownbutton': DropDownButtonComponent,
        'ejs-button': ButtonComponent
    },
    data: function() {
        return {
          hostUrl : 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/',
          settings: {showRuler: true},
          documentName : 'Form  Fields',
          documentTitle: 'Untitled Document',
          iconStyle: 'float:right;background: transparent;box-shadow:none;border-color: transparent;border-radius: 2px;color:inherit;font-size:12px;text-transform:capitalize;margin-top:4px;height:28px;font-weight:400;font-family:inherit;',
            titileStyle: 'text-transform:capitalize;font-weight:400;font-family:inherit;text-overflow:ellipsis;white-space:pre;overflow:hidden;user-select:none;cursor:text',
            openIconCss: 'e-de-icon-Open e-de-padding-right',
            printIconCss: 'e-de-icon-Print e-de-padding-right',
            exportIconCss: 'e-de-icon-Download e-de-padding-right',
            exportItems: [
                { text: 'Syncfusion Document Text (*.sfdt)', id: 'sfdt' },
                { text: 'Word Document (*.docx)', id: 'word' },
                { text: 'Word Template (*.dotx)', id: 'dotx' },
                { text: 'Plain Text (*.txt)', id: 'txt' },
            ],
            fileMenuItems: [
                'New',
                'Open',
                {
                    text: 'Export',
                    id: 'custom_item',
                    iconCss: 'e-icons e-export',
                    items: [
                        { id: 'sfdt', text: 'Syncfusion Document Text (*.sfdt)' },
                        { id: 'docx', text: 'Word Document (*.docx)' },
                        { id: 'dotx', text: 'Word Template (*.dotx)' },
                        { id: 'text', text: 'Plain Text (*.txt)' },
                        { id: 'pdf', text: 'PDF (*.pdf)' },
                        { id: 'html', text: 'HyperText Markup Language (*.html)' },
                        { id: 'rtf', text: 'Rich Text Format (*.rtf)' },
                        { id: 'md', text: 'Markdown (*.md)' },
                        { id: 'odt', text: 'OpenDocument Text (*.odt)' },
                        { id: 'wordml', text: 'Word XML Document (*.xml)' },
                    ],
                },
                'Print',
            ]
        };
    },  
    provide:{
        DocumentEditorContainer:[Toolbar,Ribbon]
    },
      methods: {
        fileMenuItemClick: function (args) {
            if (args.item.id) {
                let value = args.item.id;
                let documentEditor = this.$refs.doceditcontainer.ej2Instances.documentEditor;
                switch (value) {
                    case 'docx':
                        documentEditor.save(documentEditor.documentName === '' ? 'sample' : documentEditor.documentName, 'Docx');
                        break;
                    case 'sfdt':
                        documentEditor.save(documentEditor.documentName === '' ? 'sample' : documentEditor.documentName, 'Sfdt');
                        break;
                    case 'text':
                        documentEditor.save(documentEditor.documentName === '' ? 'sample' : documentEditor.documentName, 'Txt');
                        break;
                    case 'dotx':
                        documentEditor.save(documentEditor.documentName === '' ? 'sample' : documentEditor.documentName, 'Dotx');
                        break;
                    case 'pdf':
                        this.formatSave('Pdf');
                        break;
                    case 'html':
                        this.formatSave('Html');
                        break;
                    case 'odt':
                        this.formatSave('Odt');
                        break;
                    case 'md':
                        this.formatSave('Md');
                        break;
                    case 'rtf':
                        this.formatSave('Rtf');
                        break;
                    case 'wordml':
                        this.formatSave('Xml');
                        break;
                }
            }
        },
        onExport: function (args) {
            switch (args.item.id) {
                case 'word':
                    this.save('Docx');
                    break;
                case 'sfdt':
                    this.save('Sfdt');
                    break;
                case 'txt':
                    this.save('Txt');
                    break;
                case 'dotx':
                    this.save('Dotx');
                    break;
            }
        },
        openExportDropDown: function () {
            // tslint:disable-next-line:max-line-length
            document.getElementById('word').setAttribute('title', 'Download a copy of this document to your computer as a DOCX file.');
            // tslint:disable-next-line:max-line-length
            document.getElementById('sfdt').setAttribute('title', 'Download a copy of this document to your computer as an SFDT file.');
            // tslint:disable-next-line:max-line-length
            document.getElementById('txt').setAttribute('title', 'Download a copy of this document to your computer as a TXT file.');
            // tslint:disable-next-line:max-line-length
            document.getElementById('dotx').setAttribute('title', 'Download a copy of this document to your computer as a DOTX file.');
        },
        save: function (format) {
            // tslint:disable-next-line:max-line-length
             this.$refs.doceditcontainer.ej2Instances.documentEditor.save( this.$refs.doceditcontainer.ej2Instances.documentEditor.documentName === '' ? 'sample' :  this.$refs.doceditcontainer.ej2Instances.documentEditor.documentName, format);
        },
        formatSave: function (type) {
            let documentEditor = this.$refs.doceditcontainer.ej2Instances.documentEditor;
            let containerElement = this.$refs.doceditcontainer.ej2Instances.element;
            createSpinner({ target: containerElement });
            showSpinner(containerElement);
            let format = type;
            let url = documentEditor.serviceUrl + 'Export';
            let http = new XMLHttpRequest();
            http.open('POST', url);
            http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
            http.responseType = 'blob';
            let sfdt = {
                Content: documentEditor.serialize(),
                Filename: documentEditor.documentName,
                Format: '.' + format,
            };
            http.onload = function () {
                if (http.status === 200) {
                    let responseData = http.response;
                    let blobUrl = URL.createObjectURL(responseData);
                    let downloadLink = document.createElement('a');
                    downloadLink.href = blobUrl;
                    downloadLink.download = documentEditor.documentName + '.' + format.toLowerCase();
                    document.body.appendChild(downloadLink);
                    hideSpinner(containerElement);
                    downloadLink.click();
                    document.body.removeChild(downloadLink);
                    URL.revokeObjectURL(blobUrl);
                } else {
                    console.error('Request failed with status:', http.status);
                    hideSpinner(containerElement);
                }
            };
            http.send(JSON.stringify(sfdt));
        },
        openBtnClick: function () {
            this.$refs.uploadDocument.click();
        },
        printBtnClick: function () {
            this.$refs.doceditcontainer.ej2Instances.documentEditor.print();
        },
        titleBarKeydownEvent: function (e) {
            if (e.keyCode === 13) {
                e.preventDefault();
                document.getElementById("documenteditor_title_contentEditor").contentEditable = 'false';
                if (document.getElementById("documenteditor_title_contentEditor").textContent === '') {
                    document.getElementById("documenteditor_title_contentEditor").textContent = 'Document1';
                }
            }
        },
        titleBarBlurEvent: function (args) {
            if (document.getElementById("documenteditor_title_contentEditor").textContent === '') {
                document.getElementById("documenteditor_title_contentEditor").textContent = 'Document1';
            }
            document.getElementById("documenteditor_title_contentEditor").contentEditable = 'false';
            this.$refs.doceditcontainer.ej2Instances.documentEditor.documentName = document.getElementById("documenteditor_title_name").textContent;
        },
        titleBarClickEvent: function () {
            this.updateDocumentEditorTitle();
        },
        updateDocumentEditorTitle: function () {
            document.getElementById("documenteditor_title_contentEditor").contentEditable = 'true';
            document.getElementById("documenteditor_title_contentEditor").focus();
            window.getSelection().selectAllChildren(document.getElementById("documenteditor_title_contentEditor"));
        },
        documentChangedEvent: function () {
            var obj = this.$refs.doceditcontainer.ej2Instances.documentEditor;
            this.documentTitle = obj.documentName === '' ? 'Untitled Document' : obj.documentName;
            document.getElementById("documenteditor_title_name").textContent = obj.documentName ;
            setTimeout(() => { obj.scrollToPage(1); }, 10);
        }
    },
    mounted() {
        this.$nextTick(function () {
          var obj = this.$refs.doceditcontainer.ej2Instances.documentEditor;
          obj.open(JSON.stringify(formfields));
          obj.documentName='Form  Fields';
          this.$refs.doceditcontainer.ej2Instances.documentEditorSettings.showRuler = true;
		  this.$refs.doceditcontainer.ej2Instances.showPropertiesPane = false;
          this.$refs.doceditcontainer.ej2Instances.documentChange = () => {
                this.documentChangedEvent();
            };
       });
    }
};
</script>
```
