From f9c699b64bda75cdf4e9007c1b2a78c481ec2af3 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Fri, 21 Dec 2018 14:15:11 -0500 Subject: [PATCH] Ref #563 - return unique validation errors (prevents multiple validators from returning "this field is required", etc) --- src/fields/abstractField.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fields/abstractField.js b/src/fields/abstractField.js index b3ca671b..e6a3858f 100644 --- a/src/fields/abstractField.js +++ b/src/fields/abstractField.js @@ -1,4 +1,4 @@ -import { get as objGet, forEach, isFunction, isString, isArray, debounce, uniqueId } from "lodash"; +import { get as objGet, forEach, isFunction, isString, isArray, debounce, uniqueId, uniq as arrayUniq } from "lodash"; import validators from "../utils/validators"; import { slugifyFormID } from "../utils/schema"; @@ -107,9 +107,9 @@ export default { }); } - let handleErrors = errors => { + let handleErrors = (errors) => { let fieldErrors = []; - forEach(errors, err => { + forEach(arrayUniq(errors), err => { if (isArray(err) && err.length > 0) { fieldErrors = fieldErrors.concat(err); } else if (isString(err)) { @@ -139,7 +139,7 @@ export default { if (!isFunction(this.debouncedValidateFunc)) { this.debouncedValidateFunc = debounce( this.validate.bind(this), - objGet(this, "$parent.options.validateDebounceTime", 500) + objGet(this.schema, "validateDebounceTime", objGet(this.formOptions, "validateDebounceTime", 500)) ); } this.debouncedValidateFunc(); @@ -162,8 +162,8 @@ export default { this.schema.onChanged.call(this, this.model, newValue, oldValue, this.schema); } - if (objGet(this.$parent, "options.validateAfterChanged", false) === true) { - if (objGet(this.$parent, "options.validateDebounceTime", 0) > 0) { + if (objGet(this.formOptions, "validateAfterChanged", false) === true) { + if (objGet(this.schema, "validateDebounceTime", objGet(this.formOptions, "validateDebounceTime", 0)) > 0) { this.debouncedValidate(); } else { this.validate();