Custom validation broken in latest kendo release.

4 posts, 1 answers
  1. Brandon
    Brandon avatar
    15 posts
    Member since:
    Sep 2012

    Posted 02 May 2014 Link to this post

    I have a custom validation method configured for my grid column which is now broken in the latest release.

    Here is the source for my validation method:

    validnamevalidation: function (input) {
        if (input.is('input[data-bind="value:Name"]')) {
            input.attr("data-validnamevalidation-msg", "A team already exists with that name.");
            var passed = false;
            var currentDataItem = $("#teamsGrid").data("kendoGrid").dataItem($(input.context));
            var currentId = currentDataItem.Id;
            if (currentId == "") currentId = -1;
            $.ajax({
                async: false,
                url: currentViewModel.crudServiceBaseUrl + "CheckTeamNameBeforeAdd?teamId=" + currentId + "&name=" + input.val().trim(),
                success: function (result) {
                    if (result == "False") passed = false;
                    else passed = true;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown + '. ' + jqXHR.responseText);
                },
                complete: function (jqXHR, textStatus) {
                }
            });
            return passed;
        }
        return true;
    },


    In the latest release, the input.context variable (which I use to obtain the current data row to be validated) is now undefined.

    Is this a bug?
    Is there a workaround?
  2. Brandon
    Brandon avatar
    15 posts
    Member since:
    Sep 2012

    Posted 02 May 2014 Link to this post

    I found a workaround for my current solution considering I am using inline-editing.

    By replacing input.context with input.closest("tr"), I get the proper result. However, I now I have to change this for every custom validation rule I have made throughout my solution.

    It would be better to have this functionality restored or at least an explanation of why it was removed.
  3. Kendo UI is VS 2017 Ready
  4. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 06 May 2014 Link to this post

    Hello Brandon,

    Unfortunately,  that beside being deprecated in latest jQuery versions, we do not clam that the context property of the jQuery instance will be "correct" or always the same. To the custom validation function will be passed the input element, thus the context may be different depending on the caller. Having this in mind you should not depend on the context field but use the input itself to get reference to its container.

    Regards,
    Rosen
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. Brandon
    Brandon avatar
    15 posts
    Member since:
    Sep 2012

    Posted 09 May 2014 Link to this post

    Thanks for the reply.

    I thought this field was being populated by Kendo before the event is fired. I was mistaken.
Back to Top
Kendo UI is VS 2017 Ready