Search results

Form fields in ASP.NET MVC DocumentEditor control

20 Jan 2022 / 2 minutes to read

DocumentEditorContainer component provide support for inserting Text, CheckBox, DropDown form fields through in-built toolbar.

Form Fields

Insert form field

Form fields can be inserted using insertFormField method in editor module.

Copied to clipboard
//Insert Text form field
//Insert Checkbox form field
//Insert Drop down form field

Get form field names

All the form fields names form current document can be retrieved using getFormFieldNames().

Copied to clipboard
var formFieldsNames = documentEditor.getFormFieldNames();

Get form field properties

Form field properties can be retrieved using getFormFieldInfo().

Copied to clipboard
//Text form field
var textfieldInfo = documentEditor.getFormFieldInfo('Text1');
//Checkbox form field
var checkboxfieldInfo = documentEditor.getFormFieldInfo('Check1');
//Dropdown form field
var dropdownfieldInfo = documentEditor.getFormFieldInfo('Drop1');

Set form field properties

Form field properties can be modified using setFormFieldInfo.

Copied to clipboard
// Set text form field properties
var textfieldInfo = documentEditor.getFormFieldInfo('Text1');
textfieldInfo.defaultValue = "Hello";
textfieldInfo.format = "Uppercase";
textfieldInfo.type = "Text";

// Set checkbox form field properties
var checkboxfieldInfo = documentEditor.getFormFieldInfo('Check1');
checkboxfieldInfo.defaultValue = true;

// Set checkbox form field properties
var dropdownfieldInfo = documentEditor.getFormFieldInfo('Drop1');
dropdownfieldInfo.dropDownItems = ['One','Two', 'Three']

Export form field data

Data of the all the Form fields in the document can be exported using exportFormData.

Copied to clipboard
var formFieldDate = documentEditor.exportFormData();

Import form field data

Form fields can be prefilled with data using importFormData.

Copied to clipboard
var textformField = {fieldName: 'Text1', value: 'Hello World'};
var checkformField = {fieldName: 'Check1', value: true};
var dropdownformField = {fieldName: 'Drop1', value: 1};
//Import form field data

Reset form fields

Reset all the form fields in current document to default value using resetFormFields.

Copied to clipboard

Protect and unprotect document programmatically

Document editor provides an option to protect and unprotect document using enforceProtection and stopProtection API.

The following example code illustrates how to enforce and stop protection in Document editor container.

Copied to clipboard

    var documenteditor;
    var container;
    function onCreated() {
        var documenteditorElement = document.getElementById('container');
        container = documenteditorElement.ej2_instances[0];
        documenteditor = container.documentEditor;
        container.documentEditor.editor.enforceProtection('123', 'FormFieldsOnly');
        //stop the document protection