JavaScript/jQuery ValidationGroup API
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 ValidationGroup 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
$(function() { var validationGroupName = "sampleGroup"; $("#textBox1").dxTextBox({ name: "FirstName" }) .dxValidator({ validationRules: [ // ... ], validationGroup: validationGroupName }); $("#textBox2").dxTextBox({ name: "LastName" }) .dxValidator({ validationRules: [ // ... ], validationGroup: validationGroupName }); $("#summary").dxValidationSummary({ validationGroup: validationGroupName }); $("#button").dxButton({ validationGroup: validationGroupName //... }); });
<div id="textBox1"></div> <div id="textBox2"></div> <div id="summary"></div> <div id="button"></div>
Angular
<dx-validation-group> <dx-text-box name="FirstName"> <dx-validator> <dxi-validation-rule type="required" message="First name is required"></dxi-validation-rule> ... </dx-validator> </dx-text-box> <dx-text-box name="LastName"> <dx-validator> <dxi-validation-rule type="required" message="Last name is required"></dxi-validation-rule> ... </dx-validator> </dx-text-box> <dx-validation-summary></dx-validation-summary> <dx-button></dx-button> </dx-validation-group>
import { DxValidationGroupModule, DxTextBoxModule, DxButtonModule, DxValidatorModule } from "devextreme-angular" // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxValidationGroupModule, DxTextBoxModule, DxButtonModule, DxValidatorModule ], // ... })
AngularJS
<div dx-validation-group="{ }" ng-controller="DemoController"> <div dx-text-box="{ name: 'FirstName' }" dx-validator="{ validationRules: [ // ... ] }"> </div> <div dx-text-box="{ name: 'LastName' }" dx-validator="{ validationRules: [ // ... ] }"> </div> <div dx-validation-summary="{ }"></div> <div dx-button="{ }"></div> </div>
Knockout
<div data-bind="dxValidationGroup: { }" > <div data-bind="dxTextBox: { name: 'FirstName' }, dxValidator: { validationRules: [ // ... ] }"> </div> <div data-bind="dxTextBox: { name: 'LastName' }, dxValidator: { validationRules: [ // ... ] }"> </div> <div data-bind="dxValidationSummary: { }"></div> <div data-bind="dxButton: { }"></div> </div>
ASP.NET MVC Controls
using (Html.DevExtreme().ValidationGroup()) { @(Html.DevExtreme().TextBox() .Name("FirstName") ) @(Html.DevExtreme().TextBox() .Name("LastName") ) @(Html.DevExtreme().ValidationSummary()) @(Html.DevExtreme().Button() .Text("Validate") .OnClick(@<text> function validate (params) { params.validationGroup.validate(); } </text>) ) }
@Using (Html.DevExtreme().ValidationGroup()) @(Html.DevExtreme().TextBox() _ .Name("FirstName") ) @(Html.DevExtreme().TextBox() _ .Name("LastName") ) @(Html.DevExtreme().ValidationSummary()) @(Html.DevExtreme().Button() _ .Text("Validate") _ .OnClick("validate") ) End Using <script> function validate(params) { params.validationGroup.validate(); } </script>
See Also
You can use the DevExpress.validationEngine.validateGroup(group) method to validate a particular validation group by passing its instance as a parameter.
DevExpress.validationEngine.validateGroup($("#sampleGroup").dxValidationGroup("instance"));
In addition, you can access a validation group's configuration using the DevExpress.validationEngine.getGroupConfig(group) method. The returned configuration exposes the validators included to the group, the validate() method to validate the editors that are associated with the validators and the validated event that occurs after the group is validated.
Configuration
Name | Description |
---|---|
elementAttr |
Specifies the attributes to be attached to the widget's root element. |
height |
Specifies the widget's height. |
onDisposing |
A function that is executed before the widget is disposed of. |
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. |
width |
Specifies the widget's width. |
Methods
Name | Description |
---|---|
dispose() |
Disposes of all the resources allocated to the ValidationGroup instance. |
element() |
Gets the root widget element. |
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. |
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. |
reset() |
Resets the value and validation result of the editors that are included to the current validation group. |
validate() |
Validates rules of the validators that belong to the current validation group. |
Events
Name | Description |
---|---|
disposing |
Raised before the widget is disposed of. |
initialized |
Raised only once, after the widget is initialized. |
optionChanged |
Raised after a widget option is changed. |
If you have technical questions, please create a support ticket in the DevExpress Support Center.