Can't change default error template

2 posts, 0 answers
  1. iDoklad
    iDoklad avatar
    13 posts
    Member since:
    Jun 2012

    Posted 05 Sep Link to this post

    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.

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1966 posts

    Posted 07 Sep Link to this post

    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.
Back to Top