Skip to content

Commit

Permalink
Ref #563 - return unique validation errors (prevents multiple validat…
Browse files Browse the repository at this point in the history
…ors from returning "this field is required", etc)
  • Loading branch information
zoul0813 committed Dec 21, 2018
1 parent 9f4c72a commit f9c699b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/fields/abstractField.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit f9c699b

Please sign in to comment.