Hello! This is the code I’m working with:
$w("#iban").onCustomValidation( async(value, reject) => {
let result = await validarIBAN($w('#iban').value)
if(!result.status){
reject(result.err);
console.log($w('#iban').valid);
}
});
I have a backend function validarIBAN imported, and I want to invalidate the text input if result.status is false.
The issue is that, when I write invalid inputs, it’s going into the if but logging true, even though I just used the reject function.
Any ideas?
Thank you in advance!
Hey Dani 
Is your function in the backend returning a value? Did you try to log the “result” ? If you did, what value you’re receiving, also please share your backend function in order to debug it.
Ahmad
Hey @ahmadnasriya , thanks for answering again. My backend function is based in the node-module iban , it’s the following:
var IBAN = require('iban');
export function validarIBAN(iban){
let status = IBAN.isValid(iban);
if (status){
return ({
'status': true,
'iban': IBAN.electronicFormat(iban),
'err':null
});
}
else{
return ({
'status': false,
'iban': null,
'err': "IBAN erroni o no vàlid. Comprova'l i torna a provar"
});
}
}
Try to remove the ( ) from the return statement, try returning an object.
return {
'status': true,
'iban': IBAN.electronicFormat(iban),
'err':null
};
Hi @ahmadnasriya , thanks for anwering again.
Just tried to remove them and it keeps not working.
I’ve tried this version now in the client side:
//Client side (same BACKEND function without parentheses in return)
$w('#iban').onCustomValidation((iban,reject)=>{
console.log('validating')
validarIBAN($w('#iban').value)
.then((result)=>{
if(!result.status){
reject(result.err);
console.log('validity after reject is: ' + $w('#iban').valid.toString());
}
})
})
$w('#continue').onClick(async()=>{
$w('#iban').updateValidityIndication();
console.log('validity after reject is: ' + $w('#iban').valid.toString());
})
Returning true with values like ‘dd’ or random strings like that.
Any ideas?
Thank you!
Hello Dani 
I can’t spot an issue, let’s debug the code, log the returned result in the Frontend , also, log the status on the Backend before returning it.
In the Frontend code, try to use async/await on the custom validation function and the validarIBAN() function since it returns a promise.
$w('#iban').onCustomValidation(async(iban,reject) => {
await validarIBAN(iban)
})
Try these suggestions.
Hello Ahmad, just tried it all. Status is logging false, and result is logging an object which status is also false, but somehow, the reject function is not working, since the validity of the text input iban is still true.
Thanks!
Not even just using reject(), without any ifs, is it working… Might be an issue with reject?
Thanks
I don’t think that there’s an issue with reject, it’s working on my websites just fine, maybe something else, I need to play with the code to tell where the issue is.
Okay Ahmad, thanks again! Let me know if you find something out.
I haven’t been able to fix it, though I think it’s something related to the asynchrony of Javascript.
As I said before, the code’s working, because since status is false, it gets into the if clause but somehow, reject isn’t working.
As you said, reject isn’t the issue though, because if I only write reject() in the event handler, it works well.
Thank you again!
Hi @ahmadnasriya , have you been able to find something out?
Thank you!
Any help from somebody, please??
Hey @danieletreinonet 
I couldn’t spot any error until now, it’s almost impossible to figure out what’s going on without debugging the code by myself.
@ahmadnasriya Awesome thanks! What’s the error?
@danieletreinonet I couldn’t figure it out just by looking at it 