This is a migrated thread and some comments may be shown as answers.

Can't change default error template

1 Answer 195 Views
Validation
This is a migrated thread and some comments may be shown as answers.
iDoklad
Top achievements
Rank 1
iDoklad asked on 05 Sep 2017, 11:29 AM
I have a kendo grid with in cell editing. I extended the validator to add a new validation rule and message. This is working correctly.
 
However, I can't seem to change the default error template for the validation message. Here is the code used to extend the validator:
 
(function ($, kendo) {
    $.extend(true, kendo.ui.validator, {
        rules: {
            uniqueTagName: function (input) {
               ...
        },
        messages: {
            uniqueTagName: resources.Message_TagAlreadyExists
        },
        errorTemplate: "<span>#=message# TEST</span>"
    });
})(jQuery, kendo);

 

I can see from the console that when I look at kendo.ui.validator, the errorTemplate is changed to "<span>#=message# TEST</span>". However, when the (Name) element is validated, I get the default error template.

Through $("#Name").kendoValidator().data("kendoValidator"), i get this template:

<span class="k-widget k-tooltip k-tooltip-validation"><span class="k-icon k-warning"> </span> #=message#</span>

However,both validators have the extended rule and validation message.

I also tried to create a <span data-for="Name" class="k-invalid-msg"> as I have found somewhere in the documentation, but this seems to have no effect.

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 07 Sep 2017, 07:15 AM

Hello Radoslav,

The recommended approach for customizing a default error message would be on Model level in the C# code. For example in order to define a new error message for the required validation you can do that:

[Required(ErrorMessage="my custom error message")]
[DisplayName("Product name")]
public string ProductName
{
    get;
    set;
}

Regards,
Boyan Dimitrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Validation
Asked by
iDoklad
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or