-
Notifications
You must be signed in to change notification settings - Fork 399
Description
Hi Rick,
Trying to check valid zip from database using custom validation rule of an input field on blur.
Here is what I am trying,
validator.registerCallback('check_validpincode', function(value) {
if (checkValidPincode(value)) {
return true;
}
return false;
}).setMessage('check_validpincode', 'The Pin Code is invalid.');
In the remote call section :
function checkValidPincode(val)
{
getNewAjaxResult(val).done(function(d) {
$("._ztoken").val(d.token);
$('#pincode').removeClass('loading');
if(d.valid == 1){
return true;
}
else {
return false;
}
})
.fail(function(x){
return false;
});
}
function getNewAjaxResult(val)
{
// Show the ajax "In progress" spinner
// Check from Pin Code records, whether the pincode is valid
// If found, return true --> else return false
//var arg = 'pincode='+val;
var req_path = "./home/checkvalidpincode";
var csrfName = $("._ztoken").attr("name");
var csrfHash = $("._ztoken").val(); // CSRF hash
return $.ajax({
url: req_path,
type:'POST',
dataType: 'json',
data: {"pin":val, [csrfName]:csrfHash},
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
headers: {'X-Requested-With': 'XMLHttpRequest'},
beforeSend: function() {
$('#pincode').addClass('loading');
}
});
}
I am not able to get the return value from the validator function.
Can you please help?