All docs
V21.1
24.2
24.1
23.2
23.1
22.2
22.1
21.2
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2.
19.1
The page you are viewing does not exist in version 19.1.
18.2
The page you are viewing does not exist in version 18.2.
18.1
The page you are viewing does not exist in version 18.1.
17.2
The page you are viewing does not exist in version 17.2.
A newer version of this page is available. Switch to the current version.

JavaScript/jQuery Form - Configure Simple Items

Create a Simple Item

By default, the Form generates a simple item for each field of the formData object. In case you need to create items for specific fields only, add the names of these fields to the items array.

JavaScript
  • $(function() {
  • $("#formContainer").dxForm({
  • formData: {
  • firstName: "John",
  • lastName: "Heart",
  • position: "CEO",
  • officeNo: 901
  • },
  • items: ["firstName", "lastName", "position"]
  • });
  • });

A simple form item is a label-editor pair. The label is the field name that undergoes a slight conversion, for example, the field name "firstName" becomes the "First Name" label. For more information on configuring labels, visit the Configure Item Labels section.

The editor that will be used in a particular simple item depends on the type of data that its field contains. However, you can force an item to use an editor of your choice. For this purpose, specify the item's editorType property. To configure the editor, use the editorOptions object. Note that you also need to specify the dataField property to bind the item to a formData field.

JavaScript
  • $(function() {
  • $("#formContainer").dxForm({
  • formData: {
  • name: "John Heart",
  • hireDate: new Date(2012, 4, 13),
  • notes: "John has been in the Audio/Video industry since 1990. He has led DevAv as its CEO since 2003."
  • },
  • items: [ "name", {
  • dataField: "hireDate",
  • editorType: "dxCalendar",
  • editorOptions: {
  • value: new Date()
  • }
  • }, {
  • dataField: "notes",
  • editorType: "dxTextArea",
  • editorOptions: {
  • placeholder: "Add notes..."
  • }
  • }]
  • });
  • });

View Demo

Customize a Simple Item

If none of the available editors suit your requirements, you can define a custom one or even place anything you find useful instead. For this purpose, implement a custom template and pass it to the template property.

JavaScript
  • $(function() {
  • $("#formContainer").dxForm({
  • formData: {
  • name: "John Heart",
  • picture: "https://js.devexpress.com/Content/images/doc/21_1/PhoneJS/person2.png",
  • notes: "John has been in the Audio/Video industry since 1990. He has led DevAv as its CEO since 2003."
  • },
  • items: ["name", {
  • dataField: "notes",
  • template: function (data, itemElement) {
  • itemElement.append( $("<div id='textAreaContainer'>")
  • .dxTextArea({
  • value: data.component.option('formData')[data.dataField],
  • onValueChanged: function(e) {
  • data.component.updateData(data.dataField, e.value);
  • }
  • });
  • )
  • }
  • }, {
  • dataField: "picture",
  • template: function (data, itemElement) {
  • itemElement.append("<img src='" + data.editorOptions.value + "'>");
  • }
  • }]
  • });
  • });

View Demo View Example

A simple item can be accompanied by a line of text that gives a hint, for example, of the values that this item accepts. To specify this text, use the helpText property. If filling an item is required, assign true to its isRequired property. In this case, a special mark appears near the item. For more information, see the Additional Marks topic.

JavaScript
  • $(function() {
  • $("#formContainer").dxForm({
  • formData: {
  • name: "John Heart",
  • phone: "+1(360)684-1334"
  • },
  • items: [{
  • dataField: "name",
  • isRequired: true
  • }, {
  • dataField: "phone",
  • helpText: "Example: +1(111)111-1111"
  • }]
  • });
  • });

You can modify automatically generated items using the customizeItem function. This function is called for each item before it is rendered. To access the item, use the function's parameter. Its structure mirrors the Simple Item structure, therefore, you can modify any property available for a simple item.

JavaScript
  • $(function() {
  • $("#formContainer").dxForm({
  • formData: {
  • firstName: "John",
  • lastName: "Heart",
  • email: "jheart@dx-email.com",
  • phone: "+1(213) 555-9392"
  • },
  • customizeItem: function (item) {
  • if(item.itemType == "simple") {
  • item.label = {
  • location: "top"
  • };
  • if(item.dataField === "email" || item.dataField === "phone") {
  • item.colSpan = 3;
  • }
  • if(item.dataField === "phone") {
  • item.helpText = "Example: +1 (111) 111-1111";
  • }
  • }
  • }
  • });
  • });
NOTE
The customizeItem function is called for each item including group, tabbed and empty items, although such items can be declared only in the items array, and there is no need to customize them afterwards. Therefore, we recommend you to check the itemType property to ensure that the item you are going to customize is indeed a simple item.
See Also

Create an Unbound Simple Item

If you do not need a simple item to be bound to a formData field, create an unbound item. It can be useful if you need, for example, to hide or show some additional information. To create such an item, specify its name, but do not set its dataField property. You will be able to access the item by this name if you need to.

In the following example, the order item contains the DataGrid UI component. This UI component is shown only when the CheckBox in the show-order item is checked. Both the order and show-order items are unbound items.

JavaScript
  • $(function () {
  • var isOrderShown = false;
  • var form = $("#form").dxForm({
  • formData: {
  • firstName: "John",
  • lastName: "Smith"
  • },
  • items: [
  • "firstName", "lastName", {
  • name: "show-order",
  • label: {
  • text: "Show the order"
  • },
  • template: function (data, $itemElement) {
  • $("<div>").appendTo($itemElement).dxCheckBox({
  • value: isOrderShown,
  • onValueChanged: function(e) {
  • isOrderShown = e.value;
  • form.itemOption("order", "visible", isOrderShown);
  • }
  • });
  • }
  • }, {
  • name: "order",
  • visible: isOrderShown,
  • template: function (data, $itemElement) {
  • $("<div id='dataGrid'>")
  • .appendTo($itemElement)
  • .dxDataGrid({
  • dataSource: [{
  • productName: "DesktopLCD 19",
  • cost: 68,
  • salePrice: 110
  • }, {
  • productName: "DesktopLCD 21",
  • cost: 75,
  • salePrice: 120
  • }]
  • });
  • }
  • }
  • ]
  • }).dxForm("instance");
  • });
See Also