Pull down to refresh...
Release to refresh...
Refreshing...
-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Reporting
- AI-powered Extensions
-
Interaction
-
Report Types
-
Data binding
-
Real-life Reports
-
Layout Features
-
Report Controls
-
Web-specific Features
-
Rich Text Editor
- Overview
- Load/Save
- Document Protection
-
Templates
- Autocorrect
-
Customization
- Simple View
-
Spreadsheet
- Overview
-
Open a Document
- Export And Printing
-
Features
-
UI Customization
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
- Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
Related Demos:
Your search did not match any results.
Loading...
Form - Customize Fields at Runtime
The Form component allows you to add/remove items and specify item visibility at runtime. The Form only updates the affected items and does not re-render the entire form.
In this demo, the "Show Address" checkbox specifies the visibility of address-related fields. Review the component's code to see how to set the "HomeAddress" group's visible attribute.
Click the "Add phone" button to add a new phone editor. This action adds a new item to the items array of the "phones" group. Each phone editor contains a button that deletes it from the items array and the Form.
Was this demo helpful?
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
x
@using DevExtreme.NETCore.Demos.ViewModels
@model DynamicFormViewModel
<div class="long-title"><h3>Personal details</h3></div>
<div id="form-container">
@(Html.DevExtreme().Form<DynamicFormViewModel>()
.ID("form")
.ColCount(2)
.Items(groups => {
groups.AddGroup()
.Items(leftGroup => {
leftGroup.AddGroup()
.Caption("Personal Data")
.Items(items => {
items.AddSimpleFor(m => m.FirstName);
items.AddSimpleFor(m => m.LastName);
items.AddSimple()
.Label(l => l.Text(""))
.Editor(e =>
e.CheckBox()
.OnValueChanged("onCheckBoxValueChanged")
.Text("Show Address")
.Value(true)
);
});
leftGroup.AddGroup()
.Items(addressGroup => {
addressGroup.AddGroup()
.Name("HomeAddress")
.Caption("Home Address")
.Items(items => {
items.AddSimpleFor(m => m.Address);
items.AddSimpleFor(m => m.City);
});
});
});
groups.AddGroup()
.Name("phones-container")
.Caption("Phones")
.Items(rightGroup => {
rightGroup.AddGroup()
.Name("phones")
.Items(items => {
items.AddSimpleFor(m => m.Phones[0])
.Label(l => l.Text("Phone 1"))
.CssClass("phone-editor")
.Editor(e =>
e.TextBox()
.Mask("+1 (X00) 000-0000")
.InputAttr("aria-label", "Mask")
.MaskRules(new { X = new JS("/[01-9]/") })
.Buttons(b =>
b.Add().Name("Trash")
.Location(TextEditorButtonLocation.After)
.Widget(w =>
w.Button()
.StylingMode(ButtonStylingMode.Text)
.Icon("trash")
.OnClick("function(e) {onTrashButtonClick(0)}")
)
)
);
items.AddSimpleFor(m => m.Phones[1])
.Label(l => l.Text("Phone 2"))
.CssClass("phone-editor")
.Editor(e =>
e.TextBox()
.Mask("+1 (X00) 000-0000")
.InputAttr("aria-label", "Mask")
.MaskRules(new { X = new JS("/[01-9]/") })
.Buttons(b =>
b.Add().Name("Trash")
.Location(TextEditorButtonLocation.After)
.Widget(w =>
w.Button()
.StylingMode(ButtonStylingMode.Text)
.Icon("trash")
.OnClick("function(e) {onTrashButtonClick(1)}")
)
)
);
});
rightGroup.AddGroup()
.Items(items => {
items.AddButton()
.HorizontalAlignment(HorizontalAlignment.Left)
.CssClass("add-phone-button")
.ButtonOptions(b =>
b.Icon("add")
.Text("Add phone")
.OnClick("onAddButtonClick")
);
});
});
})
.OnInitialized("onFormInitialized")
.OnContentReady("onFormReady")
.FormData(Model)
)
</div>
<script>
var form,
employee,
isFirstLoad = true;
function onFormInitialized(e) {
form = e.component;
}
function onFormReady(e) {
if (isFirstLoad) {
employee = e.component.option("formData");
isFirstLoad = false;
}
}
function onCheckBoxValueChanged(e) {
form.itemOption("HomeAddress", "visible", e.value);
}
function onAddButtonClick() {
employee.Phones.push("");
form.itemOption("phones-container.phones", "items", getPhonesOptions(employee.Phones));
}
function onTrashButtonClick(index) {
employee.Phones.splice(index, 1);
form.itemOption("phones-container.phones", "items", getPhonesOptions(employee.Phones));
}
function getPhonesOptions(phones) {
var options = [];
for (var i = 0; i < phones.length; i++) {
options.push(generateNewPhoneOptions(i));
}
return options;
}
function generateNewPhoneOptions(index) {
return {
dataField: "Phones[" + index + "]",
editorType: "dxTextBox",
cssClass: "phone-editor",
label: {
text: "Phone " + (index + 1)
},
editorOptions: {
mask: "+1 (X00) 000-0000",
maskRules: { "X": /[01-9]/ },
buttons: [{
name: "trash",
location: "after",
options: {
stylingMode: "text",
icon: "trash",
onClick: function () {
onTrashButtonClick(index);
}
}
}]
}
}
}
</script>
xxxxxxxxxx
xxxxxxxxxx