Form

The Form 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.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/form
Export: default
Form interactive configuration
Copy Code
Copy to Codepen
$("#form").dxForm({
});

                    

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the Form widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
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.nowebsite.com"
};
$(function () {
    $("#form").dxForm({
        formData: companyData,
        items: [
            "name", {
                itemType: "group",
                caption: "Location",
                items: ["city", "state", "zip"]
            }, {
                itemType: "group",
                caption: "Contacts",
                items: ["phone", "fax", "website"]
            }
        ]
    });
});
<div id="form"></div>
Angular
HTML
TypeScript
<dx-form
    [formData]="companyData">
    <dxi-item datafield="name"></dxi-item>
    <dxi-item
        itemType="group"
        caption="Location">
        <dxi-item dataField="city"></dxi-item>
        <dxi-item dataField="state"></dxi-item>
        <dxi-item dataField="zip"></dxi-item>
    </dxi-item>
    <dxi-item
        itemType="group"
        caption="Contacts">
        <dxi-item dataField="phone"></dxi-item>
        <dxi-item dataField="fax"></dxi-item>
        <dxi-item dataField="website"></dxi-item>
    </dxi-item>
</dx-form>
import { DxFormModule } from "devextreme-angular";
// ...
export class AppComponent {
    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.nowebsite.com"
    };
}
@NgModule({
    imports: [
        // ...
        DxFormModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-form="{
        formData: companyData,
        items: [
            'name', {
                itemType: 'group',
                caption: 'Location',
                items: ['city', 'state', 'zip']
            }, {
                itemType: 'group',
                caption: 'Contacts',
                items: ['phone', 'fax', 'website']
            }
        ]
    }"></div>
</div>
angular.module("DemoApp", ["dx"])
    .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.nowebsite.com"
        };
    });
Knockout
HTML
JavaScript
<div data-bind="dxForm: {
    formData: companyData,
    items: [
        'name', {
            itemType: 'group',
            caption: 'Location',
            items: ['city', 'state', 'zip']
        }, {
            itemType: 'group',
            caption: 'Contacts',
            items: ['phone', 'fax', 'website']
        }
    ]
}"></div>
var viewModel = {
    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.nowebsite.com"
    }
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().Form()
    .FormData(new {
        ID = 1,
        Name = "Super Mart of the West",
        City = "Bentonville",
        State = "Arkansas",
        Zip = 727161232,
        Phone = "(800) 555-2797",
        Fax = "(800) 555-2171",
        Website = "http://www.nowebsite.com"
    })
    .Items(formItems => {
        formItems.AddSimple().DataField("Name");
        formItems.AddGroup().Caption("Location").Items(locationItems => {
            locationItems.AddSimple().DataField("City");
            locationItems.AddSimple().DataField("State");
            locationItems.AddSimple().DataField("Zip");
        });
        formItems.AddGroup().Caption("Contacts").Items(contactsItems => {
            contactsItems.AddSimple().DataField("Phone");
            contactsItems.AddSimple().DataField("Fax");
            contactsItems.AddSimple().DataField("Website");
        });
    })
)
@(Html.DevExtreme().Form() _
    .FormData(New With {
        .Id = 1,
        .Name = "Super Mart of the West",
        .City = "Bentonville",
        .State = "Arkansas",
        .Zip = 727161232,
        .Phone = "(800) 555-2797",
        .Fax = "(800) 555-2171",
        .Website = "http://www.nowebsite.com"
    }) _
    .Items(Sub(formItems)
        formItems.AddSimple().DataField("name")
        formItems.AddGroup().Caption("Location").Items(Sub(locationItems)
            locationItems.AddSimple().DataField("City")
            locationItems.AddSimple().DataField("State")
            locationItems.AddSimple().DataField("Zip")
        End Sub)
        formItems.AddGroup().Caption("Contacts").Items(Sub(contactsItems)
            contactsItems.AddSimple().DataField("Phone")
            contactsItems.AddSimple().DataField("Fax")
            contactsItems.AddSimple().DataField("Website")
        End Sub)
    End Sub)
)  
See Also

Configuration

An object defining configuration options for the Form widget.

Name Description
accessKey

Specifies the shortcut key that sets focus on the widget.

activeStateEnabled

Specifies 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.

colCountByScreen

Specifies dependency between the screen factor and the count of columns in the form layout.

customizeItem

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

disabled

Specifies whether the widget responds to user interaction.

elementAttr

Specifies the attributes to be attached to the widget's root element.

focusStateEnabled

Specifies whether the widget can be focused using keyboard navigation.

formData

Provides the Form's data. Gets updated every time form fields change.

height

Specifies the widget's height.

hint

Specifies text for a hint that appears when a user pauses on the widget.

hoverStateEnabled

Specifies whether the widget changes its state when a user pauses on it.

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 function that is executed when the widget's content is ready and each time the content is changed.

onDisposing

A function that is executed before the widget is disposed of.

onEditorEnterKey

A function that is executed when the Enter key has been pressed while an editor is focused.

onFieldDataChanged

A function that is executed when the value of a formData object field is changed.

onInitialized

A function that is executed only once, after the widget is initialized.

onOptionChanged

A function that is executed after a widget option is changed.

optionalMark

The text displayed for optional fields.

readOnly

Specifies whether all editors on the form are read-only. Applies only to non-templated items.

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

Switches the widget to a right-to-left representation.

screenByWidth

Specifies the function returning the screen factor depending on the screen width.

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 number of the element when the Tab key is used for navigating.

validationGroup

Gives a name to the internal validation group.

visible

Specifies whether the widget is visible.

width

Specifies the widget's width.

Methods

This section describes members used to manipulate a widget.

Name Description
beginUpdate()

Prevents the widget from refreshing until the endUpdate() method is called.

defaultOptions(rule)

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

dispose()

Disposes of all the resources allocated to the Form instance.

element()

Gets the root widget element.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

focus()

Sets focus on the widget.

getEditor(dataField)

Gets an editor instance. Takes effect only if the form item is visible.

getInstance(element)

Gets the instance of a widget found using its DOM node.

instance()

Gets the widget's instance. Use it to access other methods of the widget.

itemOption(id)

Gets a form item's configuration.

itemOption(id, option, value)

Updates the value of a single item option.

itemOption(id, options)

Updates the values of several item options.

off(eventName)

Detaches all event handlers from a single event.

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

on(eventName, eventHandler)

Subscribes to an event.

on(events)

Subscribes to events.

option()

Gets all widget options.

option(optionName)

Gets the value of a single option.

option(optionName, optionValue)

Updates the value of a single option.

option(options)

Updates the values of several options.

registerKeyHandler(key, handler)

Registers a handler to be executed when a user presses a specific key.

repaint()

Repaints the widget. Call it if you made modifications that changed the widget's state to invalid.

resetValues()

Resets the editor's value to undefined.

updateData(data)

Updates formData fields and the corresponding editors.

updateData(dataField, value)

Updates a formData field and the corresponding editor.

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

Raised when the widget's content is ready.

disposing

Raised before the widget is disposed of.

editorEnterKey

Raised when the Enter key has been pressed while an editor is focused.

fieldDataChanged

Raised when the value of a formData object field is changed.

initialized

Raised only once, after the widget is initialized.

optionChanged

Raised after a widget option is changed.

See Also

Item Types

This section describes item types available in the Form widget.