getting value of the id of a model within a custom validator

2 posts, 0 answers
  1. Jacob
    Jacob avatar
    4 posts
    Member since:
    Aug 2012

    Posted 29 Aug 2012 Link to this post

    I have successfully implemented a custom AJAX validator in a grid for the popup editor. The purpose of the validator is to check whether a login field is unique in a database table. However, in order to do this the server side check the code needs to know the value of the ID field of the model in question so it can exclude itself from the uniqueness check. Is there any way of retrieving the ID, or the value any other field of the model being edited within the custom validator?

    A snippet of my code is here:

    login:{
    type: "string",
    validation: {
    checkLoginUnique: function(input) {
    if ($(input).attr("name") == "login")
    {
    var result;
    $.ajax({
    url: "<?php echo Yii::app()->createUrl('/lasso/users/checkUnique'); ?>",
    async: false,
    data: {
    login: $(input).val()
    },
    success: function(response) {
    result = response;
    }
    });
    return result;
    }
    return true;
    }

    }
  2. Jacob
    Jacob avatar
    4 posts
    Member since:
    Aug 2012

    Posted 29 Aug 2012 Link to this post

    I found my own solution. Just get the model from the selected row of the grid:

        var grid = $("#grid").data("kendoGrid");
    var model = grid.dataItem(grid.select());
    var id = null;
    if (typeof(model) != "undefined")
    id = model.id;
  3. Kendo UI is VS 2017 Ready
Back to Top