Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
@using DevExtreme.MVC.Demos.ViewModels
@model FormViewModel
@(Html.DevExtreme().Form<FormViewModel>()
.FormData(Model)
.Items(items => {
items.AddGroup()
.Caption("Employee Details")
.ColCount(2)
.Items(groupItems => {
groupItems.AddSimpleFor(m => m.FirstName)
.Label(l => l.Template(new JS("nameLabel")))
.Editor(e => e
.TextBox()
.InputAttr("aria-label", "Name")
.Disabled(true)
);
groupItems.AddSimpleFor(m => m.Position)
.Label(l => l.Template(new JS("positionLabel")))
.Editor(e => e
.SelectBox()
.InputAttr("aria-label", "Position")
.DataSource(new[] {
"HR Manager",
"IT Manager",
"CEO",
"Controller",
"Sales Manager",
"Support Manager",
"Shipping Manager"
})
.SearchEnabled(true)
.Value("")
)
.ValidationRules(r => r
.AddRequired()
.Message("Position is required")
);
groupItems.AddSimpleFor(m => m.LastName)
.Label(l => l.Template(new JS("nameLabel")))
.Editor(e => e
.TextBox()
.InputAttr("aria-label", "Last Name")
.Disabled(true)
);
groupItems.AddSimpleFor(m => m.HireDate)
.Label(l => l.Template(new JS("eventLabel")))
.Editor(e => e
.DateBox()
.InputAttr("aria-label", "Hire Date")
.Value(new JS("null"))
.Width("100%")
)
.ValidationRules(r => r
.AddRequired()
.Message("Hire date is required")
);
groupItems.AddSimpleFor(m => m.BirthDate)
.Label(l => l.Template(new JS("eventLabel")))
.Editor(e => e
.DateBox()
.InputAttr("aria-label", "Birth Date")
.Disabled(true)
.Width("100%")
)
.IsRequired(false);
groupItems.AddSimpleFor(m => m.Address)
.Label(l => l.Template(new JS("addressLabel")));
groupItems.AddSimpleFor(m => m.Notes)
.Label(l => l.Template(new TemplateName("notesTemplate")))
.ColSpan(2)
.Editor(e => e
.TextArea()
.InputAttr("aria-label", "Notes")
.Height(90)
.MaxLength(200)
);
groupItems.AddSimpleFor(m => m.Phone)
.Label(l => l.Template(new JS("phoneLabel")))
.Editor(e => e
.TextBox()
.Mask("+1 (X00) 000-0000")
.InputAttr("aria-label", "Phone")
.MaskRules(new { X = new JS("/[02-9]/") })
);
groupItems.AddSimpleFor(m => m.Email)
.Label(l => l.Template(new JS("emailLabel")));
});
})
.OnContentReady("validateForm")
)
@using (Html.DevExtreme().NamedTemplate("notesTemplate")) {
<div id='template-content'>
<i
id="helpedInfo"
class="dx-icon dx-icon-info"
></i>
Additional
<br>
Notes:
</div>
@(Html.DevExtreme().Tooltip()
.Target("#helpedInfo")
.ShowEvent("mouseenter")
.HideEvent("mouseleave")
.ContentTemplate(@<text><div id='tooltip-content'>This field must not exceed 200 characters</div></text>)
)
}
<script>
function nameLabel(data) {
return $(`<div><i class='dx-icon dx-icon-user'}></i>${data.text}</div>`);
}
function positionLabel(data) {
return $(`<div><i class='dx-icon dx-icon-info'}></i>${data.text}</div>`);
}
function eventLabel(data) {
return $(`<div><i class='dx-icon dx-icon-event'}></i>${data.text}</div>`);
}
function phoneLabel(data) {
return $(`<div><i class='dx-icon dx-icon-tel'}></i>${data.text}</div>`);
}
function addressLabel(data) {
return $(`<div><i class='dx-icon dx-icon-home'}></i>${data.text}</div>`);
}
function emailLabel(data) {
return $(`<div><i class='dx-icon dx-icon-email'}></i>${data.text}</div>`);
}
function validateForm(e) {
e.component.validate();
}
</script>
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using DevExtreme.MVC.Demos.Models.SampleData;
using DevExtreme.MVC.Demos.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Web.Mvc;
namespace DevExtreme.MVC.Demos.Controllers {
public class FormController : Controller {
public ActionResult CustomizeItem() {
return View(new FormViewModel {
ID = 1,
FirstName = "John",
LastName = "Heart",
Phone = "360-684-1334",
Position = "CEO",
BirthDate = DateTime.Parse("1964/03/16"),
HireDate = DateTime.Parse("1995/01/15"),
Notes = "John has been in the Audio/Video industry since 1990. He has led DevAv as its CEO since 2003.\r\n\r\nWhen not working hard as the CEO, John loves to golf and bowl. He once bowled a perfect game of 300.",
Address = "351 S Hill St., Los Angeles, CA",
Email = "jheart@dx-email.com"
});
}
}
}
#helpedInfo {
color: #42a5f5;
}
#tooltip-content {
font-size: 14px;
font-weight: bold;
}
#template-content {
display: inline-flex;
}
To change the default settings, declare an item configuration object. Use the dataField property to bind an item to a field in the formData object. Use the editorType property to specify an item's data editor or configure the editor in the editorOptions object. You can also specify any other properties described in the SimpleItem section.
To customize item labels, use the label.template property. The demo uses this property to add icons to the labels. Refer to the Additional Notes item's implementation for instructions on how to add an icon with a tooltip to the label.
This demo shows how to specify editorOptions, editorType, validationRules, and colSpan properties for simple items in a Form component.