Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registercallback for input field failing in ajax return #219

Open
ZopCoder opened this issue Mar 2, 2021 · 0 comments
Open

Registercallback for input field failing in ajax return #219

ZopCoder opened this issue Mar 2, 2021 · 0 comments

Comments

@ZopCoder
Copy link

ZopCoder commented Mar 2, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant