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

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

1 Answer 190 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Jacob
Top achievements
Rank 1
Jacob asked on 29 Aug 2012, 12:57 PM
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;
}

}

1 Answer, 1 is accepted

Sort by
0
Jacob
Top achievements
Rank 1
answered on 29 Aug 2012, 01:51 PM
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;
Tags
Validation
Asked by
Jacob
Top achievements
Rank 1
Answers by
Jacob
Top achievements
Rank 1
Share this question
or