Form

The dxForm widget represents fields of a data object as a collection of label-editor pairs. These pairs can be arranged in several groups, tabs and columns.

Form interactive configuration
Copy Code
Copy to Codepen
$("#form").dxForm({
});

                    

You can create the widget using one of the following approaches.

  • jQuery
    Use the dxForm jQuery plug-in.

    HTML
    <div id="form">
    </div>
    JavaScript
    var companyData = {
        id: "1",
        name: "Super Mart of the West",
        city: "Bentonville",
        state: "Arkansas",
        zip: 72716,
        phone: "(800) 555-2797",
        fax: "(800) 555-2171",
        website: "http://www.nowebsitesupermart.com"
    }
    $("#form").dxForm({
        formData: companyData,
        colCount: 2
    });
  • Knockout
    Add a div element and apply dxForm binding to this element.

    HTML
    <div data-bind="dxForm: {
        formData: companyData,
        colCount: 2
    }"></div>
    JavaScript
    var myViewModel = {
        companyData: {
            id: "1",
            name: "Super Mart of the West",
            city: "Bentonville",
            state: "Arkansas",
            zip: 72716,
            phone: "(800) 555-2797",
            fax: "(800) 555-2171",
            website: "http://www.nowebsitesupermart.com"
        }
    }
    ko.applyBindings(myViewModel);
  • AngularJS
    Add a div element and apply the dx-form directive to this element.

    HTML
    <div ng-controller="demoController">
        <div dx-form="{
            formData: companyData,
            colCount: 2
        }"></div>
    </div>
    JavaScript
    var myApp = angular.module('myApp', ['dx']);
    myApp.controller("demoController", function ($scope) {
        $scope.companyData = {
            id: "1",
            name: "Super Mart of the West",
            city: "Bentonville",
            state: "Arkansas",
            zip: 72716,
            phone: "(800) 555-2797",
            fax: "(800) 555-2171",
            website: "http://www.nowebsitesupermart.com"
        };
    });
    angular.element(document).ready(function () {
        angular.bootstrap(document, ['myApp']);
    });

Note that DevExtreme widgets require you to link the jQuery and Globalize libraries to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

Configuration

An object defining configuration options for the dxForm widget.

Name Description
accessKey

Specifies a shortcut key that sets focus on the widget element.

activeStateEnabled

A Boolean value specifying whether or not the widget changes its state when interacting with a user.

alignItemLabels

Specifies whether or not all root item labels are aligned.

alignItemLabelsInAllGroups

Specifies whether or not item labels in all groups are aligned.

colCount

The count of columns in the form layout.

customizeItem

Specifies a function that customizes a form item after it has been created.

disabled

A Boolean value specifying whether or not the widget can respond to user interaction.

focusStateEnabled

Specifies whether or not the widget can be focused.

formData

An object providing data for the form.

height

Specifies the height of the widget.

hint

Specifies the text of the hint displayed for the widget.

hoverStateEnabled

A Boolean value specifying whether or not the widget changes its state when being hovered by an end user.

items

Holds an array of form items.

labelLocation

Specifies the location of a label against the editor.

minColWidth

The minimum column width used for calculating column count in the form layout.

onContentReady

A handler for the contentReady event.

onDisposing

A handler for the disposing event.

onEditorEnterKey

A handler for the editorEnterKey event.

onFieldDataChanged

A handler for the fieldDataChanged event.

onInitialized

A handler for the initialized event.

onOptionChanged

A handler for the optionChanged event.

optionalMark

The text displayed for optional fields.

readOnly

Specifies whether or not all editors on the form are read-only.

requiredMark

The text displayed for required fields.

requiredMessage

Specifies the message that is shown for end-users if a required field value is not specified.

rtlEnabled

Specifies whether or not the current component supports a right-to-left representation.

scrollingEnabled

A Boolean value specifying whether to enable or disable form scrolling.

showColonAfterLabel

Specifies whether or not a colon is displayed at the end of form labels.

showOptionalMark

Specifies whether or not the optional mark is displayed for optional fields.

showRequiredMark

Specifies whether or not the required mark is displayed for required fields.

showValidationSummary

Specifies whether or not the total validation summary is displayed on the form.

tabIndex

Specifies the widget tab index.

visible

A Boolean value specifying whether or not the widget is visible.

width

Specifies the width of the widget.

Methods

This section describes members used to manipulate a widget.

Name Description
beginUpdate()

Prevents the component from refreshing until the endUpdate method is called.

defaultOptions(rule)

Specifies the device-dependent default configuration options for this component.

element()

Returns the root HTML element of the widget.

endUpdate()

Enables the component to refresh after the beginUpdate method call.

focus()

Sets focus on the widget.

getEditor(field)

Returns an editor instance associated with the specified formData field or name of a form item.

instance()

Returns an instance of this component class.

itemOption(field, option, value)

Updates the value of a form item option.

itemOption(field, options)

Updates the values of form item options.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

registerKeyHandler(key, handler)

Registers a handler when a specified key is pressed.

repaint()

Redraws the widget.

resetValues()

Resets the editor's value to undefined.

updateData(data)

Updates the specified fields of the formData object and the corresponding editors on the form.

updateData(dataField, value)

Updates the specified field of the formData object and the corresponding editor on the form.

updateDimensions()

Updates the dimensions of the widget contents.

validate()

Validates the values of all editors on the form against the list of the validation rules specified for each form item.

Events

This section describes events fired by this widget.

Name Description
contentReady

Fires when widget content is ready.

disposing

Fires when the widget is being removed.

editorEnterKey

Fires after a user presses the Enter key when an editor is focused.

fieldDataChanged

Fires after the value of a formData object field has been changed.

initialized

Fires when the widget is initialized.

optionChanged

Fires after an option of the component is changed.

Simple Item

This article describes configuration options of a simple form item.

A simple form item is an editor-label pair usually bound to a formData object field used to display and modify this field.

You can also create a simple item without binding it to a formData field. For example, it can be a check box that allows a user to confirm his agreement to process entered data.

For detailed information on creating simple items, see the Create Simple Items topic.

Group Item

This article describes configuration options of a group form item.

A group form item is a section consisting of a caption and child form items. You can customize the layout options for each group separately.

For detailed information on creating group items, see the Create Group Items topic.

Tabbed Item

This article describes configuration options of a tabbed form item.

For detailed information on creating tabbed items, see the Create Tabbed Items topic.

Empty Item

This article describes configuration options of an empty form item.

For detailed information on creating empty items, see the Create Empty Items topic.