# Telerik Validation Tooltip for Blazor

The [Telerik Validation Tooltip for Blazor](https://www.telerik.com/blazor-ui/validationtooltip) displays validation errors as tooltips that point to the problematic input component. The tooltips show on mouse over. Validaton tooltips serve the same purpose as inline [validation messages](https://www.telerik.com/blazor-ui/documentation/components/validation/message), but as popups, they don't take up space on the page.

## Basics

To use a Telerik Validation Tooltip:

1. Add the `<TelerikValidationTooltip>` tag.
2. Set the `TargetSelector` parameter to a CSS selector that points to the desired element in the Form.
3. (optional) Set the `Position` parameter to define on which side of the target the tooltip shows. Refer to the [Position article for the Telerik Blazor Tooltip component](https://www.telerik.com/blazor-ui/documentation/components/tooltip/position) for details.
4. Set the `For` parameter in the same way as with a standard Blazor `<ValidationMessage>`. There are two options:
   * If the `TelerikValidationTooltip` is in the same component as the Form or if the Form model object is available, use a lambda expression that points to a property of the Form model.
     ```RAZOR.skip-repl
     <TelerikTextBox Id="first-name" />
     <TelerikValidationTooltip For="@(() => Customer.FirstName)"
                               TargetSelector="#first-name" />

     @code {
         private CustomerModel Customer { get; set; } = new();

         public class CustomerModel
         {
             public string FirstName { get; set; } = string.Empty;
         }
     }
     ```
   * If the [validation message is in a child component](https://www.telerik.com/blazor-ui/documentation/knowledge-base/inputs-validation-child-component) that receives a `ValueExpression`, set the `For` parameter directly to the expression, without a lambda.
     ```RAZOR.skip-repl
     <TelerikTextBox Id="first-name" />
     <TelerikValidationTooltip For="@FirstNameExpression"
                               TargetSelector="#first-name" />

     @code {
         [Parameter]
         public Expression<System.Func<string>>? FirstNameExpression { get; set; }
     }
     ```

Refer to the following sections for additional information and examples with the [Telerik Form](https://www.telerik.com/blazor-ui/documentation/components/validation/tooltip#using-with-telerikform) and standard [Blazor `<EditForm>`](https://www.telerik.com/blazor-ui/documentation/components/validation/tooltip#using-with-editform).

## Using with TelerikForm

The Telerik Form can [display built-in validation tooltips](https://www.telerik.com/blazor-ui/documentation/components/form/validation#validation-message-type). You may need to define `<TelerikValidationTooltip>` components manually when you want to:

* Use [form item templates](https://www.telerik.com/blazor-ui/documentation/components/form/formitems/template). In this case, [add the validation tooltip in the form item template](https://www.telerik.com/blazor-ui/documentation/components/form/formitems/template#example).
* Customize the validation tooltips, for example, change their rendering with a [validation tooltip template](https://www.telerik.com/blazor-ui/documentation/components/validation/tooltip#template). In this case, add the validation tooltip inside a [Form item template](https://www.telerik.com/blazor-ui/documentation/components/form/formitems/template#example).

The following example sets a `Tooltip` `ValidationMessageType` on the Form. This is not required, but makes the validation user experience the same for `FirstName` and `LastName` properties, as the latter is not using an explicit `<TelerikValidationTooltip>`.

> caption Use Telerik ValidationTooltip in a Telerik Form

<demo metaUrl="client/validation/tooltip/example-1/" height="420"></demo>

## Using with EditForm

In an existing Blazor `EditForm`, replace the `<ValidationMessage>` tags with `<TelerikValidationTooltip>` tags. The `For` parameter is set in the same way for both validation components.

> caption Use Telerik Validation Tooltip in an EditForm

<demo metaUrl="client/validation/tooltip/example-2/" height="420"></demo>

## Position

The position of the ValidationTooltip is configured in the [same way as for the Telerik Tooltip component for Blazor](https://www.telerik.com/blazor-ui/documentation/components/tooltip/position).

## Template

The Telerik ValidationTooltip allows you to customize its rendering with a nested `<Template>` tag. The template `context` is an `IEnumerable<string>` collection of all messages for the validated model property.

> caption Using ValidationTooltip Template

<demo metaUrl="client/validation/tooltip/example-3/" height="420"></demo>

## Class

Use the `Class` parameter of the Validation Tooltip to add a custom CSS class to `div.k-animation-container`. This element wraps the `div.k-tooltip` and element and its child `div.k-tooltip`.

<demo metaUrl="client/validation/tooltip/example-4/" height="420"></demo>

## See Also

* [Live Demo: Validation](https://demos.telerik.com/blazor-ui/validation/overview)
* [Validate Inputs in Child Components](https://www.telerik.com/blazor-ui/documentation/knowledge-base/inputs-validation-child-component)
* [Telerik ValidationSummary](https://www.telerik.com/blazor-ui/documentation/components/validation/summary)
* [Telerik ValidationMessage](https://www.telerik.com/blazor-ui/documentation/components/validation/message)
