@@ -53,7 +53,7 @@ function toErrorSchema(errors) {
5353 if ( Array . isArray ( parent . __errors ) ) {
5454 // We store the list of errors for this node in a property named __errors
5555 // to avoid name collision with a possible sub schema field named
56- // "errors" (see `validate. createErrorHandler`).
56+ // "errors" (see `createErrorHandler`).
5757 parent . __errors = parent . __errors . concat ( message ) ;
5858 } else {
5959 parent . __errors = [ message ] ;
@@ -62,7 +62,7 @@ function toErrorSchema(errors) {
6262 } , { } ) ;
6363}
6464
65- export function toErrorList ( errorSchema ) {
65+ function toErrorList ( errorSchema ) {
6666 return Object . keys ( errorSchema ) . reduce ( ( acc , key ) => {
6767 const field = errorSchema [ key ] ;
6868 if ( "__errors" in field ) {
@@ -79,7 +79,7 @@ function createErrorHandler(formData) {
7979 const handler = {
8080 // We store the list of errors for this node in a property named __errors
8181 // to avoid name collision with a possible sub schema field named
82- // "errors" (see `utils. toErrorSchema`).
82+ // "errors" (see `toErrorSchema`).
8383 __errors : [ ] ,
8484 addError ( message ) {
8585 this . __errors . push ( message ) ;
@@ -105,9 +105,18 @@ function unwrapErrorHandler(errorHandler) {
105105}
106106
107107/**
108- * This function processes the formData with a user `validate` contributed
109- * function, which receives the form data and an `errorHandler` object that
110- * will be used to add custom validation errors for each field.
108+ * This function processes the formData against:
109+ *
110+ * 1. A JSON schema object, then
111+ * 2. An optional `validate` contributed function, which receives the form data
112+ * and an `errorHandler` object used to add custom validation errors for each
113+ * field.
114+ *
115+ * It returns a Promise resolving with an object exposing the following
116+ * properties:
117+ *
118+ * - `errors`: The list of encountered validation errors;
119+ * - `errorSchema`: An error tree matching the formData structure.
111120 *
112121 * @return {Promise }
113122 */
@@ -121,8 +130,8 @@ export default function validateFormData(formData, schema, customValidate) {
121130
122131 const errorHandler = createErrorHandler ( formData ) ;
123132 return Promise . resolve ( customValidate ( formData , errorHandler ) )
124- . then ( UserErrorHandler => {
125- const userErrorSchema = unwrapErrorHandler ( UserErrorHandler ) ;
133+ . then ( userErrorHandler => {
134+ const userErrorSchema = unwrapErrorHandler ( userErrorHandler ) ;
126135 const newErrorSchema = mergeObjects ( errorSchema , userErrorSchema , true ) ;
127136 // XXX: The errors list produced is not fully compliant with the format
128137 // exposed by the jsonschema lib, which contains full field paths and other
0 commit comments