However, using this template will result in a thrown validation error even if all constraints are satisfied.
The source for VanillaValidator revealed the problem. toJSON needs to return null if there are no errors. Apparently, the framework uses the output of this method to determine if any errors are present. If null is returned, then there are no errors.
Therefore, one way to address the issue would be to update the documentation as follows:
// must return null if no errors are present
toJSON () {
return this.errors.length ? this.errors : null
}
Documentation gives this template for a custom formatter:
However, using this template will result in a thrown validation error even if all constraints are satisfied.
The source for VanillaValidator revealed the problem.
toJSON
needs to returnnull
if there are no errors. Apparently, the framework uses the output of this method to determine if any errors are present. If null is returned, then there are no errors.Therefore, one way to address the issue would be to update the documentation as follows: