New to Telerik UI for Blazor? Download free 30-day trial

FormItem Template - Custom Editors

This article explains how to customize the editor of a single Form item. To customize the rendering and item structure of the whole Form, check the article Form Template for All Items.


Form item templates enables the app to:

To use a form item template, add a <Template> tag inside the FormItem.

When using a Form item template, the following FormItem parameters are ignored, because the Form expects the template content to provide suitable replacements:

  • EditorType
  • Hint
  • Id
  • LabelText

Validation Messages and Styling

The FormItem Template replaces all the Form item's built-in rendering, which includes validation messages and form item labels. You can use the Telerik validation tools to display the desired validation UI, or even use the standard Blazor ValidationMessage component.

The Telerik Blazor Form applies red color to the labels of invalid Form items. To preserve this behavior in Form item templates:

  1. Set the FormItem Field parameter, which is otherwise not required when using a Template.
  2. Use a <label class="k-label k-form-label"> element inside the <Template>.


The sample below shows how to:

  • Define custom editor components inside a FormItem Template.
  • (optional) Preserve the built-in HTML rendering inside the template for consistent form item layout (<label> and <div> tags).
  • (optional) Preserve the built-in label styling for invalid form items (FormItem Field parameters and <label> classes).
  • (optional) Use validation messages inside Form item templates (<TelerikValidationMessage>).

Using Form Item Templates

<TelerikForm Model="@FormModel">
        <FormItem Field="@nameof(TravelDestination.Country)">
                <label for="country" class="k-label k-form-label">Destination Country</label>
                <div class="k-form-field-wrap">
                    <TelerikDropDownList @bind-Value="@FormModel.Country"
                                         DefaultText="Select Country"
                            <DropDownListPopupSettings Height="auto" />
                    <TelerikValidationMessage For="@(() => FormModel.Country)" />
        <FormItem Field="@nameof(TravelDestination.City)">
                <label for="city" class="k-label k-form-label">Destination City</label>
                <div class="k-form-field-wrap">
                    <TelerikComboBox Data="@CityData"
                                     Placeholder="Select City"
                            <ComboBoxPopupSettings Height="auto" />
                    <TelerikValidationMessage For="@(() => FormModel.City)" />
        <FormItem Field="@nameof(TravelDestination.FirstTime)">
                <label for="firsttime" class="k-label k-form-label">First Time Visit</label>
                <div class="k-form-field-wrap">
                    <TelerikSwitch @bind-Value="@FormModel.FirstTime"
                                   OffLabel="No" />

@code {
    private TravelDestination FormModel { get; set; } = new();

    private List<string> DropDownData { get; } = new List<string>()

    private List<string> CityData
            switch (FormModel.Country)
                case "Bulgaria":
                    return new List<string>() { "Sofia", "Plovdiv", "Varna", "Burgas" };
                case "Italy":
                    return new List<string>() { "Rome", "Milan", "Naples", "Turin" };
                case "Greece":
                    return new List<string>() { "Athens", "Thessaloniki", "Patras", "Piraeos" };
                    return new List<string>();

    public class TravelDestination
        [Required(ErrorMessage = "Country is required")]
        public string Country { get; set; }

        [Required(ErrorMessage = "City is required")]
        public string City { get; set; }

        public bool FirstTime { get; set; }

See Also

In this article