Form Overview

Telerik UI for ASP.NET Core Ninja image

The Form is part of Telerik UI for ASP.NET Core, a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

The Telerik UI Form TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI Form widget.

The Telerik UI Form for ASP.NET Core allows you to generate and manage forms. Through a variety of configuration options, it makes creating and customizing forms a seamless experience. Achieve the desired form appearance by using default or custom editors, choose layout and orientation, display the editors in groups and columns, and configure validation.

Initializing the Form

The following example demonstrates how to define the Form.

        @(Html.Kendo().Form<MyApplication.Models.UserViewModel>()
        .Name("form")
        .HtmlAttributes(new { action = "Index", method = "POST" })
        .Validatable(v =>
        {
            v.ValidateOnBlur(true);
            v.ValidationSummary(vs => vs.Enable(true));
        })
        .Items(items =>
        {
            items.AddGroup()
                .Label("Registration Form")
                .Items(i =>
                {
                    i.Add()
                        .Field(f => f.FirstName)
                        .Label(l => l.Text("First Name:"));
                    i.Add()
                        .Field(f => f.LastName)
                        .Label(l => l.Text("Last Name:"));
                });
        });
    )

    @model Kendo.Mvc.Examples.Models.Form.UserViewModel

    <kendo-form name="form" form-data="@Model" method="POST" asp-controller="Form" asp-action="Tag_Helper">
        <validatable validate-on-blur="true" validation-summary="true" />
        <form-items>
            <form-item type="group">
                <item-label text="Registration Form" />
                <form-items>
                    <form-item field="FirstName">
                        <item-label text="First Name:" />
                    </form-item>
                    <form-item field="LastName">
                        <item-label text="Last Name:" />
                    </form-item>
                </form-items>
            </form-item>
        </form-items>
    </kendo-form>

Referencing Existing Instances

The following example demonstrates a basic configuration for the Form and how to get a reference to an existing Form client-side instance:

    @(Html.Kendo().Form<MyApplication.Models.UserViewModel>()
        .Name("exampleForm")
        .HtmlAttributes(new { action = "Index", method = "POST" })
        .Validatable(v =>
        {
            v.ValidateOnBlur(false);
            v.ValidationSummary(vs => vs.Enable(true));
        })
        .Items(items =>
        {
            items.AddGroup()
                .Label("Registration Form")
                .Items(i =>
                {
                    i.Add()
                        .Field(f => f.FirstName)
                        .Label(l => l.Text("First Name:"));
                    i.Add()
                        .Field(f => f.LastName)
                        .Label(l => l.Text("Last Name:"));
                    i.Add()
                        .Field(f => f.Password)
                        .Label(l => l.Text("Password:"))
                        .Hint("Hint: enter alphanumeric characters only.");
                    i.Add()
                        .Field(f => f.Email)
                        .Label(l => l.Text("Email:"));
                    i.Add()
                        .Field(f => f.Agree)
                        .Label(l => l.Text("Agree to Terms:"));
                });
        });
    )

    <script>
    $(document).ready(function () {
    // The Name() of the Form is used to get its client-side instance.
    var form = $("#exampleForm").data("kendoForm");
    });
    </script>
    <kendo-form name="tagHelperForm" form-data="@Model" method="POST" asp-controller="Form" asp-action="Tag_Helper">
        <validatable validate-on-blur="true" validation-summary="true" />
        <form-items>
            <form-item type="group">
                <item-label text="Registration Form" />
                <form-items>
                    <form-item field="FirstName">
                        <item-label text="First Name:" />

                    </form-item>
                    <form-item field="LastName">
                        <item-label text="Last Name:" />

                    </form-item>
                </form-items>
            </form-item>
        </form-items>
    </kendo-form>

    <script>
        $(document).ready(function () {
        // The Name() of the Form is used to get its client-side instance.
        var form = $("#tagHelperForm").data("kendoForm");
        });
    </script>

Functionality and Features

Events

You can subscribe to all events of the Form component.

The following example shows a Form configured to handle its validate, submit and clear events.

    <kendo-form name="exampleForm" form-data="@Model" method="POST" asp-action="Items" on-validate-field="onFormValidateField" on-submit="onFormSubmit" on-clear="onFormClear">
        <validatable validate-on-blur="true" validation-summary="true" />
        <form-items>
            <form-item type="group">
                <item-label text="Registration Form" />
                <form-items>
                    <form-item field="TextBox">
                        <item-label text="TextBox:"/>
                        <textbox-editor placeholder="TextBox"></textbox-editor>
                    </form-item>
                    <form-item field="NumericTextBox">
                        <item-label text="NumericTextBox:" />
                        <numerictextbox-editor></numerictextbox-editor>
                    </form-item>  
                </form-items>
            </form-item>
            <form-item type="group">
                 <form-item field="MaskedTextBox">
                        <item-label text="MaskedTextBox:" optional="true" />
                        <maskedtextbox-editor></maskedtextbox-editor>
                    </form-item>
                    <form-item field="DatePicker">
                        <item-label text="DatePicker:" optional="true" />
                    </form-item>
            </form-item>
        </form-items>
    </kendo-form>

    <script>
        function onFormValidateField(e) {
            $("#validation-success").html("");
        }

        function onFormSubmit(e) {
            e.preventDefault();
            $("#validation-success").html("<div class='k-messagebox k-messagebox-success'>Form data is valid!</div>");
        }

        function onFormClear(e) {
            $("#validation-success").html("");
        }
    </script>

See Also

In this article