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

Disable some Kendo messages and show default instead

2 Answers 399 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Volker
Top achievements
Rank 1
Volker asked on 17 Feb 2014, 10:17 PM
Hi,

I am using Kendo Validation throughout my ASP.NET MVC project. I have a problem with email-validation which cost me all the evening:

I use this attribute for my C# property
[EmailAddress(ErrorMessageResourceType=typeof(Resources.PersonResources), ErrorMessageResourceName = "MailAddressInvalid", ErrorMessage = null)]
public string MailAddress { get; set; }


Without Kendo validation, this leads to the following: On validating the Mailaddress, the error message which I defined in the resource file is shown. 

Now with Kendo: It seems Kendo overrides this custom message with a Kendo one, something like "<HTML element id> is not a valid mailaddress".

But I need the one I defined in the resource! So, is a way to disable the Kendo default messages for inputs of type email? I know I could do some custom code to get the message from the input element (something like that could work), but I really hope there is a more intelligent way...

Thanks!

2 Answers, 1 is accepted

Sort by
0
Volker
Top achievements
Rank 1
answered on 17 Feb 2014, 10:22 PM
Answer to myself - this does the trick:

var validator = $(this).kendoValidator(
                {
                    validateOnBlur: false,
                    messages: {
                        email: function (input) {
                            return input.attr("data-val-email");
                        }
                    }
                }).data("kendoValidator");
0
Loren
Top achievements
Rank 1
answered on 16 Jul 2014, 02:46 PM
I know this is a bit old. But i just spend sometime trying to make this work. Below is a more Global way so you dont have to set that custom rule up each time you want to validate an email in your system. Also I put in a fall-back in case the [EmailAddress] DataAnnotation is missed.

(function ($, kendo) {
    var dateValidation = function (input) {
        if (input.filter("[data-val-date]").length > 0) {
            return input.val() === "" || kendo.parseDate(input.val(), ["MMddyyyy", "MMddyy", "MM/dd/yyyy", "MM/dd/yy"]) !== null;
        }
        return true;
    };
 
    $.extend(true, kendo.ui.validator, {
        rules: {
            date: dateValidation,
            mvcdate: dateValidation
        },
        messages: {
            email: function (input) {
                if (input.attr("data-val-email")) {
                    return input.attr("data-val-email");
                }
                else {
                    return "{0} is not valid email";
                }
            }
        }
    });
})(jQuery, kendo);
Tags
Validation
Asked by
Volker
Top achievements
Rank 1
Answers by
Volker
Top achievements
Rank 1
Loren
Top achievements
Rank 1
Share this question
or