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:
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;
}
}
}
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;
}
}
}