Configuration

An object defining configuration options for the Form widget.

accessKey

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

Type: String
Default Value: null

The accessKey option value is passed to the accesskey attribute of the actual HTML element of the widget.

activeStateEnabled

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

Type: Boolean
Default Value: false

This option is used when the widget is displayed on a platform whose guidelines include the active state change for widgets.

alignItemLabels

Specifies whether or not all root item labels are aligned.

Type: Boolean
Default Value: true

Show Example:
AngularJS
Knockout
jQuery

alignItemLabelsInAllGroups

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

Type: Boolean
Default Value: true
NOTE
This option applies only to those simple items that are nested within a group item. Thus, we recommend that you do not leave any simple items ungrouped if you need a consistent alignment throughout the Form.
Show Example:
AngularJS
Knockout
jQuery

colCount

The count of columns in the form layout.

Type: Number|String
Default Value: 1
Accepted Values: 'auto'

When configuring the widget using ASP.NET MVC Wrappers, you can specify this option using the Mode enum, which accepts the value Auto.

Show Example:
AngularJS
Knockout
jQuery

colCountByScreen

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

Type: Object
Default Value: undefined

customizeItem

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

Type: function
Function parameters:
item: Form item
Provides access to the item instance.

If you did not define form items using the items option, the Form widget creates them automatically according to the structure of an object passed to the formData option. The customizeItem option enables you to modify options of each generated item before this item is rendered. Each generated item passed to this function as an argument has a Simple Item structure.

If the items option contains definition for form items, you usually do not need to pass a function to the customizeItem option because you can customize items before passing them to the items option. However, if you assign a function to this option, it will be called for each item. In this case, an item can have structure corresponding to any of the following item types.

  • Simple
    A standard item consisting of a label and an editor widget used to specify a value of the associated data field.

  • Group
    An item representing a container of other form items.

  • Tabbed
    An item representing a tabbed container of other form items.

  • Empty
    An empty item used to add a space between neighboring form items.

disabled

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

Type: Boolean
Default Value: false

Create an observable variable and assign it to this option to specify the availability of the widget at runtime.

Show Example:
AngularJS
Knockout
jQuery

elementAttr

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

Type: Object
Default Value: {}

When you configure this option using a server-side wrapper, pass a dictionary as shown in the following code.

Razor C#
Razor VB
@(Html.DevExtreme()
    // other widget options
    // ...
    .ElementAttr(new Dictionary<string, object>() {
        { "id", "elementId" },
        { "class", "class-name" },
        // ...
    })
)
@(Html.DevExtreme().WidgetName() _
    .ElementAttr(New Dictionary(Of String, Object) From {
        { "id", "elementId" },
        { "class", "class-name" }
    })
)

focusStateEnabled

Specifies whether or not the widget can be focused.

Type: Boolean
Default Value: false

formData

An object providing data for the form.

Type: Object
Default Value: {}

height

Specifies the height of the widget.

Type: Number|String| function
Return Value: Number|String
The widget height.
Default Value: undefined

The option can hold a value of the following types.

  • number
    The height of the widget in pixels

  • string
    A CSS measurement of the widget height (e.g., "55px", "80%", "auto" and "inherit")

  • function
    A function returning the widget height, e.g.,

    JavaScript
    height: function () {
        return baseHeight - 10 + "%";
    }

hint

Specifies the text of the hint displayed for the widget.

Type: String
Default Value: undefined

hoverStateEnabled

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

Type: Boolean
Default Value: false

items

Holds an array of form items.

Type: Array
Default Value: undefined

The array passed to this option can hold items of the following types.

  • Simple
    A standard item consisting of a label and an editor widget used to specify a value of the associated data field.

  • Group
    An item representing a container of another form items.

  • Tabbed
    An item representing a tabbed container of another form items.

  • Empty
    An empty item used to add a space between neighboring items.

When configuring the widget using ASP.NET MVC Wrappers, declare the items in the following manner.

Razor C#
Razor VB
@(Html.DevExtreme().Form()
    .FormData(Model.Data)
    .Items(rootItems => {
        rootItems.AddSimple().DataField("EmployeeID"); // Adds a simple item
        rootItems.AddEmpty(); // Adds an empty item
        rootItems.AddGroup().Caption("General Info") // Adds a group item
            .Items(groupItems => {
                groupItems.AddSimple().DataField("FirstName");
                // ...
            });
        rootItems.AddTabbed() // Adds a tabbed item
            .Tabs(tabs => {
                tabs.Add().Title("Address")
                    .Items(addressItems => {
                        addressItems.AddSimple().DataField("Country");
                        // ...
                    });
                tabs.Add().Title("Phone")
                    // ...
            });
    })
)
@(Html.DevExtreme().Form() _
    .FormData(Model.Data) _
    .Items(Sub(rootItems)
        rootItems.AddSimple().DataField("EmployeeID") ' Adds a simple item
        rootItems.AddEmpty() ' Adds an empty item
        ' Adds a group item
        rootItems.AddGroup().Caption("General Info") _
            .Items(Sub(groupItems)
                groupItems.AddSimple().DataField("FirstName")
                ' ...
            End Sub)
        ' Adds a tabbed item
        rootItems.AddTabbed() _
            .Tabs(Sub(tabs)
                tabs.Add().Title("Address") _
                    .Items(Sub(addressItems)
                        addressItems.AddSimple().DataField("Country")
                        ' ...
                    End Sub)
                tabs.Add().Title("Phone")
                    ' ...
            End Sub)
    End Sub)
)
Show Example:
AngularJS
Knockout
jQuery

labelLocation

Specifies the location of a label against the editor.

Type: String
Default Value: 'left'
Accepted Values: 'left' | 'right' | 'top'

When configuring the widget using ASP.NET MVC Wrappers, specify this option using the FormLabelLocation enum. This enum accepts the following values: Left, Right and Top.

Show Example:
AngularJS
Knockout
jQuery

minColWidth

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

Type: Number
Default Value: 200

This option makes sense only if the colCount option is set to 'auto'.

NOTE
The actual column width equals the widget width divided by the column count.
Show Example:
AngularJS
Knockout
jQuery

onContentReady

A handler for the contentReady event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the widget instance.
element: jQuery
An HTML element of the widget.
model: Object
Provides access to the data that is available for binding against the element. Available only in the Knockout approach.
Default Value: null

Assign a function to perform a custom action when widget content is ready.

onDisposing

A handler for the disposing event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the widget instance.
element: jQuery
An HTML element of the widget.
model: Object
Provides access to the data that is available for binding against the element. Available only in the Knockout approach.
Default Value: null

Assign a function to perform a custom action when the widget is being removed.

NOTE
The function assigned to this option is executed only if the widget is removed using the remove(), empty(), or html() jQuery methods.

onEditorEnterKey

A handler for the editorEnterKey event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the form instance.
element: jQuery
An HTML element of the form.
model: Object
Provides access to the data that is available for binding against the element. Available only in the Knockout approach.
dataField: String
The path to the formData object field associated with the current editor.
Default Value: null

Assign a function to perform a custom action after a user presses the Enter key when an editor is focused.

onFieldDataChanged

A handler for the fieldDataChanged event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the form instance.
element: jQuery
An HTML element of the form.
model: Object
Provides access to the data that is available for binding against the element. Available only in the Knockout approach.
dataField: String
The path to the formData object field whose value has been changed.
value: Object
The new value of the field.
Default Value: null

Assign a function to perform a custom action after the value of a formData object field has been changed.

Show Example:
AngularJS
Knockout
jQuery

onInitialized

A handler for the initialized event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the widget instance.
element: jQuery
An HTML element of the widget.
Default Value: null

Assign a function to perform a custom action when the widget is initialized.

onOptionChanged

A handler for the optionChanged event.

Type: function
Function parameters:
e: Object
Provides function parameters.
Object structure:
component: Object
Provides access to the widget instance.
name: String
Specifies the name of the option whose value is changed.
fullName: String
Specifies a full name of the option whose value is changed. The full name is formed by concatenating the names of the options that are presented in the hierarchy of the given option. The names are delimited by commas.
value: any
Specifies a new value for the option.
element: jQuery
An HTML element of the widget.
model: Object
Provides access to the data that is available for binding against the element. Available only in the Knockout approach.
Default Value: null

Assign a function to perform a custom action after an option of the component is changed.

optionalMark

The text displayed for optional fields.

Type: String
Default Value: 'optional'

Show Example:
AngularJS
Knockout
jQuery

readOnly

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

Type: Boolean
Default Value: false

Show Example:
AngularJS
Knockout
jQuery

requiredMark

The text displayed for required fields.

Type: String
Default Value: '*'

Show Example:
AngularJS
Knockout
jQuery

requiredMessage

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

Type: String
Default Value: '{0} is required'

rtlEnabled

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

Type: Boolean
Default Value: false

If you need to switch the display of this DevExtreme component to right-to-left, enable a specifically designed configuration option - rtlEnabled. When this option is set to true, the text flows from right to left, and the layout the component's elements is reversed. To switch the entire application/site to a right-to-left representation, use the static DevExpress.rtlEnabled field.

screenByWidth

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

Type: function
Default Value: null

The function passed to this option should take on the screen width as a parameter and return a string containing the appropriate screen factor.

JavaScript
var formOptions: {
    screenByWidth: function(width) {
        if( width < 768 )
            return 'xs';
        if( width < 992 )
            return 'sm';
        if( width < 1200 )
            return 'md';
        return 'lg';
    }
}

View Demo

scrollingEnabled

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

Type: Boolean
Default Value: false

Show Example:
AngularJS
Knockout
jQuery

showColonAfterLabel

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

Type: Boolean
Default Value: true

showOptionalMark

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

Type: Boolean
Default Value: false

Show Example:
AngularJS
Knockout
jQuery

showRequiredMark

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

Type: Boolean
Default Value: true

Show Example:
AngularJS
Knockout
jQuery

showValidationSummary

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

Type: Boolean
Default Value: false

tabIndex

Specifies the widget tab index.

Type: Number
Default Value: 0

validationGroup

Gives a name to the internal validation group.

Type: String
Default Value: undefined

In some cases, the Form editors should be validated by the Button widget. By default, these editors are collected in an unnamed validation group, what makes it impossible for the Button to validate them. In this case, give this validation group a name using the validationGroup option of the Form widget. Also, pass the same name to the validationGroup option of the Button widget.

$(function () {
    $("#formContainer").dxForm({
        // ...
        validationGroup: "groupName"
    });

    $("#buttonContainer").dxButton({
        // ...
        validationGroup: "groupName",
        onClick: function (e) {
            e.validationGroup.validate();
        }
    });
})

visible

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

Type: Boolean
Default Value: true

width

Specifies the width of the widget.

Type: Number|String| function
Return Value: Number|String
The widget width.
Default Value: undefined

The option can hold a value of the following types.

  • numeric
    The widget width in pixels.
  • string
    A CSS measurement of the widget width (e.g., "55px", "80%", "auto" and "inherit").
  • function
    The function returning the widget width. For example, see the following code.

    JavaScript
    width: function () { 
        return baseWidth - 10 + "%";
    }
NOTE
Even if the width of the widget is specified, the count of columns may depend on the screen width. For example, if the screen width is not enough to display the whole form's container, the count of columns depends on the screen width, not the container. To always use a fixed count of columns regardless of the screen width, pass an empty function to the screenByWidth option.
HTML
var formOptions: {
    ...
    screenByWidth: function() { }
}