Hi Plumsail!
I have a datatable (dtB) that needs to be validated whether the data in specific column ('MeterNo') is present in another datatable (dtA), otherwise it should return error.
I have to put 'value.forEach' inside 'fd.control('dtA')' function because if not, it executes even when it's not done getting all the data in bList yet.
fd.control('dtB').addValidator({
name: 'DBCustomValidator',
error: 'Meter no is invalid',
validate: function(value){
fd.control('dtA').ready().then(function(curVal) {
const bList= [];
var bListValue= curVal.value;
//gets all the data in bList
bListValue.forEach(function (itemB) {
bList.push(item.MeterNo);
});
//validate if itemA.MeterNo in bList
value.forEach(function(itemA) {
if (bList.indexOf(itemA.MeterNo) == -1) {
//alert('false');
return false;
}
else{
//alert('true');
}
});
return true;
});
}
});
It always return false, even when it didn't went into 'return false' statement, I tried to put the validation inside fd.validators too but same action happens.
Also, when I used debugger, the error already shows before the line with 'return'