gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

Form Validation Error Message #735

Open AniketParabAtDure opened 4 years ago

AniketParabAtDure commented 4 years ago

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!!