Skip to content

Commit

Permalink
fixes #345 - declare debouncedValidateFunc and set it when debouncedV…
Browse files Browse the repository at this point in the history
…alidate() is called... vue 2.2.0 prevents you from attaching methods/properties to components that have not been declared
  • Loading branch information
zoul0813 committed Dec 5, 2017
1 parent 776aff1 commit ee684f0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 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, each, isFunction, isString, isArray, debounce } from "lodash";
import { uniqueId, get as objGet, each, isFunction, isString, isArray, debounce } from "lodash";
import validators from "../utils/validators";
import { slugifyFormID } from "../utils/schema";

Expand All @@ -24,7 +24,8 @@ export default {

data() {
return {
errors: []
errors: [],
debouncedValidateFunc: null
};
},

Expand Down Expand Up @@ -66,9 +67,6 @@ export default {

if (this.$parent.options && this.$parent.options.validateAfterChanged === true) {
if (this.$parent.options.validateDebounceTime > 0) {
if (!this.debouncedValidate)
this.debouncedValidate = debounce(this.validate.bind(this), this.$parent.options.validateDebounceTime);

this.debouncedValidate();
} else {
this.validate();
Expand All @@ -81,6 +79,7 @@ export default {

methods: {
validate(calledParent) {
console.log('validating', performance.now());
this.clearValidationErrors();

if (this.schema.validator && this.schema.readonly !== true && this.disabled !== true) {
Expand Down Expand Up @@ -130,7 +129,14 @@ export default {

return this.errors;
},

debouncedValidate() {
if(!isFunction(this.debouncedValidateFunc)) {
console.log('debouncedValidate', 'config', objGet(this, '$parent.optionsvalidateDebounceTime', 500));
this.debouncedValidateFunc = debounce(this.validate.bind(this), objGet(this, '$parent.options.validateDebounceTime', 500));
}
console.log('debouncedValidate', performance.now());
this.debouncedValidateFunc();
},
clearValidationErrors() {
this.errors.splice(0);
},
Expand Down

0 comments on commit ee684f0

Please sign in to comment.