gitana/alpaca

Form Validation Error Message

AniketParabAtDure opened this issue · 0 comments

Hi there,
Its been a while i am using the alphacajs. But recently i have ran into a problem with validation which is i am unaware of its solution.
E.g: I have three input fields as A, B and C,
Suppose i have assign a value in A = 10; Now i want to put the validation such that the sum of B and C should not be greater than A. i have written the logic as follow:

`
dataElementOption.fields['B'].validator = function(callback) {
let valueOfA = this.getParent().childrenByPropertyId['A'].getValue();
let valueOfB = this.getValue()
let valueOfC = this.getParent().childrenByPropertyId['C'].getValue();

if(valueOfA == (valueOfB + valueOfC)) {
	callback({
		status: false,
		message: 'value mismatch'
	});
} else {
	callback({
		status: true
	});
}

}
dataElementOption.fields['C'].validator = function(callback) {
let valueOfA = this.getParent().childrenByPropertyId['A'].getValue();
let valueOfB = this.getValue()
let valueOfC = this.getParent().childrenByPropertyId['C'].getValue();

if(valueOfA == (valueOfB + valueOfC)) {
	callback({
		status: false,
		message: 'value mismatch'
	});
} else {
	callback({
		status: true
	});
}

}
`

Now challenge here is , when I am entering value of B and the validation is proper i.e when the value of A is matched with (B +C ) then validation error of B is disappear, I want is, when I am entering the value of either B or C when the validation is proper i.e A == (B +C) then the error message for both B and C should be disappear.

Please help!!