Tuesday, July 1, 2014

Knockout discover validation problem

Sometimes when you use knockout to build form with validation, You will find errors more than 0 although no message appeared.
Issue: You added validation without binding the contolor
To find property which cause this problem you need to iterate through object properties to find property cause this error using the following code:

var allValidatablesAreValid = true;
for (var property in self)
{
    if (self.hasOwnProperty(property) && self[property]["isValid"]) {
        allValidatablesAreValid = allValidatablesAreValid && self[property].isValid();
    }
    // You can add an early bail out here:
    // if (!allValidatablesAreValid) { break; }
}