ValidationGroup

The widget that is used in the Knockout and AngularJS approaches to combine the editors to be validated.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js

Use the ValidationGroup widget to combine the editors to be validated, the Button widget to validate these editors on button click and the ValidationSummary widget to display validation errors occurred in these editors.

NOTE
Nested validation groups are not supported.

You can create the ValidationGroup widget using one of the following approaches.

  • jQuery
    Use the validationGroup option in the widgets in which you need to specify a validation group.

    HTML
    <div id="textBox1"></div>
    <div id="textBox2"></div>
    <div id="summary"></div>
    <div id="button"></div>
    JavaScript
    var validationGroup = "sampleGroup";
     $("#textBox1").dxTextBox({})
        .dxValidator({
            validationRules: [],
            validationGroup: validationGroup
        });
    $("#textBox2").dxTextBox({})
        .dxValidator({
            validationRules: [],
            validationGroup: validationGroup
        });
    $("#summary").dxValidationSummary({
        validationGroup: validationGroup
    });
    $("#button").dxButton({
        validationGroup: validationGroup
        //...
    });
  • Knockout
    Add a div element and apply the dxValidationGroup binding to this element.

    HTML
    <div data-bind="dxValidationGroup : {}" >
        <div data-bind="dxTextBox: { },
            dxValidator: { validationRules: [] }">  
        </div>
        <div data-bind="dxTextBox: { },
            dxValidator: { validationRules: [] }"> 
        </div>  
        <div data-bind="dxValidationSummary: { }"></div>
        <div data-bind="dxButton: { }"></div>
    </div>
  • AngularJS
    Add a div element and apply the dx-validation-group directive to this element.

    HTML
    <div dx-validation-group="{}" ng-controller="demoController">
        <div dx-text-box="{  }"
            dx-validator="{ validationRules:  }">  
        </div>
        <div dx-text-box="{  }"
            dx-validator="{ validationRules:  }">  
        </div>
        <div dx-validation-summary="{  }"></div>
        <div dx-button="{ }"></div>
    </div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

See Also

You can use the DevExpress.validationEngine.validateGroup(group) method to validate a particular validation group by passing its instance as a parameter.

JavaScript
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

An object defining configuration options for the ValidationGroup widget.

Name Description
height

Specifies the height of the widget.

onDisposing

A handler for the disposing event.

onInitialized

A handler for the initialized event.

onOptionChanged

A handler for the optionChanged event.

width

Specifies the width of the widget.

Methods

This section describes members used to manipulate the widget.

Name Description
element()

Returns the root HTML element of the widget.

instance()

Returns an instance of this component class.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

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

This section describes events fired by this widget.

Name Description
disposing

Fires when the widget is being removed.

initialized

Fires when the widget is initialized.

optionChanged

Fires after an option of the component is changed.