Validate and Submit an HTML Form

NOTE: In MVC projects, you can configure the same features using server-side wrappers. See this topic for details.

Commonly, editors nested into an HTML form are supposed to be validated on the client and then submitted to the server. The Button widget supports this scenario out of the box. Place the Button on the HTML form and set the useSubmitBehavior option to true.

HTML
<form action="/Login" method="post">
    <div id="login"></div>
    <div id="password"></div>
    <div id="validateAndSubmit"></div>
</form>
JavaScript
$(function() {
    $("#login").dxTextBox({
        name: "Login"
    }).dxValidator({
        validationRules: [
            { type: "required" }
        ]
    });

    $("#password").dxTextBox({
        name: "Password",
        mode: "password"
    }).dxValidator({
        validationRules: [
            { type: "required" }
        ]
    });

    $("#validateAndSubmit").dxButton({
        text: "Submit",
        type: "success",
        useSubmitBehavior: true
    });
});

Note that the name option of the TextBox widgets in the previous code specifies the name attribute of the underlying <input> element.

DevExtreme editors may belong to different validation groups. To specify which group the Button must validate, use the validationGroup option. If you do not set this option, the Button validates all editors whose validation group is not specified.

NOTE: Although the Button may validate different validation groups, it always submits a definite HTML form - the one in which it is nested. To avoid mixing up validated and submitted values, we recommend that a single HTML form contain only a single validation group.

See Also