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

Custom validation broken in latest kendo release.

3 Answers 21 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 02 May 2014, 07:03 PM
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?

3 Answers, 1 is accepted

Sort by
0
Brandon
Top achievements
Rank 1
answered on 02 May 2014, 07:40 PM
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.
0
Accepted
Rosen
Telerik team
answered on 06 May 2014, 10:47 AM
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!
 
0
Brandon
Top achievements
Rank 1
answered on 09 May 2014, 02:41 PM
Thanks for the reply.

I thought this field was being populated by Kendo before the event is fired. I was mistaken.
Tags
Validation
Asked by
Brandon
Top achievements
Rank 1
Answers by
Brandon
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or