I have a very simple logic and I have written conditions on that, I find the logic perfectly fine but it is always giving false results. I have three fields immediate limit, hold limit and LDC. So the condition is when immediate limit and hold one limit are numeric values sum of them should be less than LDC and individual values of each limits should also be less than LDC.(When the limit values are not numeric they return a negative no.)
Here's my code:
immediateLimitError: boolean = false;
hold1LimitError: boolean = false;
ldcLimitError: boolean = false;
sumOflimitVal: any;
changedLdc!: any;
changedImmediateLimit!: any;
changedHold1Limit!: any;
private instantiateValidation(row: any) {
this.newHoldSchedule = this.formBuilder.group({
immediatereleaseForm: [(row.hold1ReleaseAmt != null ? row.hold1ReleaseAmt : ' '), Validators.required],
ldcForm: [(row.ldcAmt != null ? row.ldcAmt : ' ')],
holdOneLimitForm: [(row.hold2ReleaseAmt != null ? row.hold2ReleaseAmt : ' '), Validators.required]
});
this.changedImmediateLimit = row.hold1ReleaseAmt;
this.changedHold1Limit = row.hold2ReleaseAmt;
this.changedLdc = row.ldcAmt;
this.newHoldSchedule.get('immediatereleaseForm')!.valueChanges.subscribe(val => {
this.changedImmediateLimit = val;
if(this.changedHold1Limit >= 0 || val >= 0 ){
if((val + this.changedHold1Limit) > this.changedLdc ||
val > this.changedLdc ||
this.changedHold1Limit > this.changedLdc){
this.immediateLimitError = true;
}
else{
this.immediateLimitError = false;
}
}
});
this.newHoldSchedule.get('holdOneLimitForm')!.valueChanges.subscribe(val => {
this.changedHold1Limit = val;
if(this.changedImmediateLimit >= 0 || val >= 0 ){
if((val + this.changedImmediateLimit) > this.changedLdc ||
val > this.changedLdc ||
this.changedImmediateLimit > this.changedLdc){
this.hold1LimitError = true;
}
else{
this.hold1LimitError = false;
}
}
});
this.newHoldSchedule.get('ldcForm')!.valueChanges.subscribe(val => {
this.changedLdc = val;
if(this.changedImmediateLimit >= 0 || this.changedHold1Limit >= 0 ){
if(val < (this.changedImmediateLimit + this.changedHold1Limit) ||
this.changedHold1Limit > val ||
this.changedImmediateLimit > val){
this.ldcLimitError = true;
}
else{
this.ldcLimitError = false;
}
}
});
}
if(this.immediateLimitError || this.hold1LimitError || this.ldcLimitError){
this.displayError('The sum of Immediate Release limit and Hold 1 Limit exceeds LDC');
event.preventDefault();
}
This code works on some values and some values it is giving false results. I tried debugging and changing the conditions but it doesn't work how I want it to work. Any help would be appreciated. thanks
Aucun commentaire:
Enregistrer un commentaire