Can't find validator object for custom validator

2 posts, 0 answers
  1. Jake
    Jake avatar
    1 posts
    Member since:
    Jul 2013

    Posted 06 May 2015 Link to this post

    We have a kendo Grid, and then we have an editor template, which is named after the view model.

    Inside the viewModel we have this:


    [Required( ErrorMessage = "Please enter a name")]

    public string Name{ get; set; }


    Then inside the javascript, I create another custom rule like this :

                    var form = $("#AdhocGroupForm")

                                    messages: {
                                                    nameexists: "This name already exists, please choose another"
                                    rules: {
                                                    nameexists: function(input) {
                                                                    if ("[name=Name]")) {
                                                                                     return input.val() === "Tom";
                                                                    return true;


    Of course, this does nothing right now. I'm simply trying to set this up and get to the point where it's called, then I'll flesh it out to check if the provided name exists, via AJAX. However, it's not called, and that is part of the issue.

    The other part is that when I do this:

                    var validator = $("#AdhocGroupForm").kendoValidator().data("kendoValidator");

    I expect to get an object that I can call 'validate' on ( I assume this is what I need to do to trigger validation although some things I've seen make me think it will fire on each keypress ). However, this returns null. kendoValidator() returns an object, but this has no validate method, either. I believe this is my core issue, I don't have a validator to work with.The form and textbox html in my page looks like this:


                    <form action="/AdhocGroup/AdhocGroupForm/AdhocGroupForm" data-role="validator" method="post" novalidate="novalidate">
                    <input class="input k-textbox" data-val="true" data-val-nameexists="data-val-nameexists" data-val-required="Please enter a name" id="Name" name="Name" style="width: 200px;" type="text" value="" data-bind="value:Name">

    The validation for the required field, with my custom error message, works fine.This is my first day using these validators, so it's possible I've missed something obvious. Thanks for any advice.

  2. Alexander Valchev
    Alexander Valchev avatar
    2895 posts

    Posted 08 May 2015 Link to this post

    Hi Jake,

    The following code will re-initialize the validation and reset all the previously configured custom rules and messages.

    var validator = $("#AdhocGroupForm").kendoValidator().data("kendoValidator");

    Please remove the code marked in red and let me know if the issue still persists.

    Alexander Valchev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top