Skip to content

Commit 5c48f52

Browse files
author
Lionel Bijaoui
committed
Merge remote-tracking branch 'upstream/master' into v3
# Conflicts: # dist/vfg-core.css # dist/vfg-core.js # dist/vfg.css # dist/vfg.js # package-lock.json # package.json # src/fields/abstractField.js # src/fields/core/fieldInput.vue # src/fields/core/fieldSelect.vue # src/fields/core/fieldSubmit.vue # src/formGenerator.vue # src/utils/validators.js # test/unit/specs/util.js
2 parents 056d9db + 1300882 commit 5c48f52

15 files changed

+477
-225
lines changed

.eslintrc.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ module.exports = {
1515
extends: ["eslint:recommended", "plugin:vue/base"],
1616
plugins: ["prettier"],
1717
rules: {
18-
indent: ["warn", "tab", { SwitchCase: 1 }],
19-
quotes: ["warn", "double"],
20-
semi: ["error", "always"],
21-
"no-var": ["error"],
22-
"no-console": ["off"],
23-
"no-unused-vars": ["warn"],
18+
indent: [1, "tab", { SwitchCase: 1 }],
19+
quotes: [1, "double"],
20+
semi: [2, "always"],
21+
"no-var": [2],
22+
"no-console": [0],
23+
"no-unused-vars": [1],
2424
"no-throw-literal": 0,
25-
// TODO reactivate after stabilisation
26-
eqeqeq: [1, "smart"],
27-
"spaced-comment": 1,
28-
"prettier/prettier": 1
25+
eqeqeq: [2, "smart"]
2926
}
3027
};

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,54 @@
1+
<a name="2.2.0"></a>
2+
# 2.2.0 (2018-01-21)
3+
4+
* add console.log ([fa779bd](https://github.com/icebob/vue-form-generator/commit/fa779bd))
5+
* add console.log to debug ([d05818e](https://github.com/icebob/vue-form-generator/commit/d05818e))
6+
* add indent ([026439a](https://github.com/icebob/vue-form-generator/commit/026439a))
7+
* add unscape html for error message. ([20b8d9d](https://github.com/icebob/vue-form-generator/commit/20b8d9d))
8+
* added "getLabelClasses" and unit test, using the fieldClasses unit test as an example ([8c01307](https://github.com/icebob/vue-form-generator/commit/8c01307))
9+
* added labelClasses support ([acdbb6c](https://github.com/icebob/vue-form-generator/commit/acdbb6c))
10+
* added missing "id" attributes to checkbox, checklist, radios and submit ([09d44c1](https://github.com/icebob/vue-form-generator/commit/09d44c1))
11+
* added missing comma that failed in Travis ([32c7627](https://github.com/icebob/vue-form-generator/commit/32c7627))
12+
* added styleClasses support to groups ([8b6801b](https://github.com/icebob/vue-form-generator/commit/8b6801b))
13+
* addeds "styleClasses" to group schemas, reimplements #339 ([8e4b43d](https://github.com/icebob/vue-form-generator/commit/8e4b43d))
14+
* bumped vue version to 2.5.3 ([7d7c0c4](https://github.com/icebob/vue-form-generator/commit/7d7c0c4))
15+
* change the judgement ([d4bc27a](https://github.com/icebob/vue-form-generator/commit/d4bc27a))
16+
* check if field.type is undefined before appending the "field-undefined" class ([9993550](https://github.com/icebob/vue-form-generator/commit/9993550))
17+
* commit the built bundle ([45e1436](https://github.com/icebob/vue-form-generator/commit/45e1436))
18+
* commit the built dist ([12b3cf7](https://github.com/icebob/vue-form-generator/commit/12b3cf7))
19+
* commit without console.log ([79a77bd](https://github.com/icebob/vue-form-generator/commit/79a77bd))
20+
* delete console.log ([ed853a2](https://github.com/icebob/vue-form-generator/commit/ed853a2))
21+
* don't render labels when no label text is provided, proposed option 1 from #347 ([8ecc851](https://github.com/icebob/vue-form-generator/commit/8ecc851))
22+
* fix bower.json validation ([2afb4ac](https://github.com/icebob/vue-form-generator/commit/2afb4ac))
23+
* fixed null check ([7842b92](https://github.com/icebob/vue-form-generator/commit/7842b92))
24+
* fixed Vue version ([624ed92](https://github.com/icebob/vue-form-generator/commit/624ed92))
25+
* fixes #340 - "none" value set to `null`, formatValueToField checks for `isNil(value)` and returns `n ([5b42807](https://github.com/icebob/vue-form-generator/commit/5b42807)), closes [#340](https://github.com/icebob/vue-form-generator/issues/340)
26+
* fixes #341 - introduced debounce functionality into `formatValueToModel` ([a46fe31](https://github.com/icebob/vue-form-generator/commit/a46fe31)), closes [#341](https://github.com/icebob/vue-form-generator/issues/341)
27+
* fixes #345 - declare debouncedValidateFunc and set it when debouncedValidate() is called... vue 2.2. ([ee684f0](https://github.com/icebob/vue-form-generator/commit/ee684f0)), closes [#345](https://github.com/icebob/vue-form-generator/issues/345)
28+
* fixes #358 - support "validateBeforeSubmit" with async validators ([5a26ef1](https://github.com/icebob/vue-form-generator/commit/5a26ef1)), closes [#358](https://github.com/icebob/vue-form-generator/issues/358)
29+
* fixes #361 - use $event.target.valueAsNumber for number/range inputs, debounce `formatValueToModel` ([d1a8bcf](https://github.com/icebob/vue-form-generator/commit/d1a8bcf)), closes [#361](https://github.com/icebob/vue-form-generator/issues/361)
30+
* fixes #362 - `integer` validator now calls `number` validator, and returns `invalidIntegerl: "The va ([8d436be](https://github.com/icebob/vue-form-generator/commit/8d436be)), closes [#362](https://github.com/icebob/vue-form-generator/issues/362)
31+
* Groupped fields "tag" param fixed. ([9275a26](https://github.com/icebob/vue-form-generator/commit/9275a26))
32+
* moved unit test to formGenerator, as labels are managed by formGenerator and not the field component ([f102967](https://github.com/icebob/vue-form-generator/commit/f102967))
33+
* remove garbage ([17eeae5](https://github.com/icebob/vue-form-generator/commit/17eeae5))
34+
* remove the errorUnescaped property, add v-html on the error part ([ecd2ca5](https://github.com/icebob/vue-form-generator/commit/ecd2ca5))
35+
* remove uniqueId import ([c86d7dc](https://github.com/icebob/vue-form-generator/commit/c86d7dc))
36+
* removed commented out console.log statements ([e9bf285](https://github.com/icebob/vue-form-generator/commit/e9bf285))
37+
* removed console.log and fixed quotes ([025b541](https://github.com/icebob/vue-form-generator/commit/025b541))
38+
* removed indentation ([49f57b8](https://github.com/icebob/vue-form-generator/commit/49f57b8))
39+
* requested by @icebob ([2724809](https://github.com/icebob/vue-form-generator/commit/2724809))
40+
* reverted back to `schema.required` for "none selected" disabled state, per @icebob ([f562d7f](https://github.com/icebob/vue-form-generator/commit/f562d7f))
41+
* reverting back to original test ([4ba3d4a](https://github.com/icebob/vue-form-generator/commit/4ba3d4a))
42+
* Update badges ([705c6a7](https://github.com/icebob/vue-form-generator/commit/705c6a7))
43+
* Update formGenerator.vue ([3208446](https://github.com/icebob/vue-form-generator/commit/3208446))
44+
* update node-sass ([e3eee64](https://github.com/icebob/vue-form-generator/commit/e3eee64))
45+
* Update README.md ([f57faba](https://github.com/icebob/vue-form-generator/commit/f57faba))
46+
* Update README.md ([1092e01](https://github.com/icebob/vue-form-generator/commit/1092e01))
47+
* Update README.md ([9d9701b](https://github.com/icebob/vue-form-generator/commit/9d9701b))
48+
* updated tests for modified label logic ([f0c2281](https://github.com/icebob/vue-form-generator/commit/f0c2281))
49+
50+
51+
152
<a name="2.1.1"></a>
253
## 2.1.1 (2017-10-20)
354

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# vue-form-generator [![NPM version](https://img.shields.io/npm/v/vue-form-generator.svg)](https://www.npmjs.com/package/vue-form-generator) ![VueJS v2.x compatible](https://img.shields.io/badge/vue%202.x-compatible-green.svg)
22
A schema-based form generator component for Vue.js.
33

4-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/912039aa815e40de8315032519aa7e6c)](https://www.codacy.com/app/mereg-norbert/vue-form-generator?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=icebob/vue-form-generator&amp;utm_campaign=Badge_Grade)
5-
[![Build Status](https://travis-ci.org/icebob/vue-form-generator.svg?branch=master)](https://travis-ci.org/icebob/vue-form-generator)
6-
[![Coverage Status](https://coveralls.io/repos/github/icebob/vue-form-generator/badge.svg?branch=master)](https://coveralls.io/github/icebob/vue-form-generator?branch=master)
4+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d27be05a35bf459b9292b8172e314a08)](https://www.codacy.com/app/mereg-norbert/vue-form-generator_2?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=vue-generators/vue-form-generator&amp;utm_campaign=Badge_Grade)
5+
[![Build Status](https://travis-ci.org/vue-generators/vue-form-generator.svg?branch=master)](https://travis-ci.org/vue-generators/vue-form-generator)
6+
[![Coverage Status](https://coveralls.io/repos/github/vue-generators/vue-form-generator/badge.svg?branch=master)](https://coveralls.io/github/vue-generators/vue-form-generator?branch=master)
77
[![NPMS.io score](https://badges.npms.io/vue-form-generator.svg)]()
88
[![Package Quality](http://npm.packagequality.com/shield/vue-form-generator.svg)](http://packagequality.com/#?package=vue-form-generator)
9-
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ficebob%2Fvue-form-generator.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Ficebob%2Fvue-form-generator?ref=badge_shield)
9+
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvue-generators%2Fvue-form-generator.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvue-generators%2Fvue-form-generator?ref=badge_shield)
1010

11-
[![Dependency Status](https://david-dm.org/icebob/vue-form-generator.svg)](https://david-dm.org/icebob/vue-form-generator)
12-
[![devDependency Status](https://david-dm.org/icebob/vue-form-generator/dev-status.svg)](https://david-dm.org/icebob/vue-form-generator#info=devDependencies)
11+
[![Dependency Status](https://david-dm.org/vue-generators/vue-form-generator.svg)](https://david-dm.org/vue-generators/vue-form-generator)
12+
[![devDependency Status](https://david-dm.org/vue-generators/vue-form-generator/dev-status.svg)](https://david-dm.org/vue-generators/vue-form-generator#info=devDependencies)
1313
[![Downloads](https://img.shields.io/npm/dm/vue-form-generator.svg)](https://www.npmjs.com/package/vue-form-generator)
1414

1515
## Demo
@@ -205,6 +205,10 @@ VueFormGenerator supports custom fields. If you decide to release your custom fi
205205

206206
This way, it will be easier for everyone to find it. Thank you !
207207

208+
### Public Custom Fields
209+
210+
- [vue-tel-input](https://github.com/EducationLink/vue-tel-input) - International Telephone Input Boilerplate with Vue (integrated with VueFormGenerator).
211+
208212
## Contribution
209213
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.
210214

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-form-generator",
3-
"version": "2.1.1",
3+
"version": "2.2.0",
44
"homepage": "https://github.com/icebob/vue-form-generator",
55
"authors": [
66
"Icebob"

build/webpack.dev.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let rules = [
1010
loader: "eslint-loader",
1111
enforce: "pre",
1212
include: [path.resolve("src"), path.resolve("dev")],
13-
exclude: /node_modules/,
1413
options: {
1514
formatter: require("eslint-friendly-formatter")
1615
}

src/fields/abstractField.js

Lines changed: 80 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { get as objGet, each, isFunction, isString, isArray, debounce } from "lodash";
1+
import { get as objGet, forEach, isFunction, isString, isArray, debounce } from "lodash";
22
import validators from "../utils/validators";
33
import { slugifyFormID } from "../utils/schema";
44

5-
const convertValidator = validator => {
6-
console.log("validator", validator);
5+
function convertValidator(validator) {
76
if (isString(validator)) {
87
if (validators[validator] != null) return validators[validator];
98
else {
@@ -12,15 +11,16 @@ const convertValidator = validator => {
1211
}
1312
}
1413
return validator;
15-
};
14+
}
1615

1716
export default {
1817
props: ["model", "schema", "formOptions", "disabled"],
1918

2019
data() {
2120
return {
2221
errors: [],
23-
debouncedValidateFunc: null
22+
debouncedValidateFunc: null,
23+
debouncedFormatFunction: null
2424
};
2525
},
2626

@@ -37,32 +37,12 @@ export default {
3737

3838
set(newValue) {
3939
let oldValue = this.value;
40-
4140
newValue = this.formatValueToModel(newValue);
4241

43-
let changed = false;
44-
if (isFunction(this.schema.set)) {
45-
this.schema.set(this.model, newValue);
46-
changed = true;
47-
} else if (this.schema.model) {
48-
this.setModelValueByPath(this.schema.model, newValue);
49-
changed = true;
50-
}
51-
52-
if (changed) {
53-
this.$emit("model-updated", newValue, this.schema.model);
54-
55-
if (isFunction(this.schema.onChanged)) {
56-
this.schema.onChanged.call(this, this.model, newValue, oldValue, this.schema);
57-
}
58-
59-
if (this.$parent.options && this.$parent.options.validateAfterChanged === true) {
60-
if (this.$parent.options.validateDebounceTime > 0) {
61-
this.debouncedValidate();
62-
} else {
63-
this.validate();
64-
}
65-
}
42+
if (isFunction(newValue)) {
43+
newValue(newValue, oldValue);
44+
} else {
45+
this.updateModelValue(newValue, oldValue);
6646
}
6747
}
6848
}
@@ -71,54 +51,102 @@ export default {
7151
methods: {
7252
validate(calledParent) {
7353
this.clearValidationErrors();
54+
let validateAsync = objGet(this.formOptions, "validateAsync", false);
55+
56+
let results = [];
7457

7558
if (this.schema.validator && this.schema.readonly !== true && this.disabled !== true) {
7659
let validators = [];
7760
if (!isArray(this.schema.validator)) {
7861
validators.push(convertValidator(this.schema.validator).bind(this));
7962
} else {
80-
each(this.schema.validator, validator => {
63+
forEach(this.schema.validator, validator => {
8164
validators.push(convertValidator(validator).bind(this));
8265
});
8366
}
8467

85-
each(validators, validator => {
86-
let addErrors = err => {
87-
if (isArray(err)) Array.prototype.push.apply(this.errors, err);
88-
else if (isString(err)) this.errors.push(err);
89-
};
90-
91-
let res = validator(this.value, this.schema, this.model);
92-
if (res && isFunction(res.then)) {
93-
// It is a Promise, async validator
94-
res.then(err => {
95-
if (err) {
96-
addErrors(err);
68+
forEach(validators, validator => {
69+
if (validateAsync) {
70+
results.push(validator(this.value, this.schema, this.model));
71+
} else {
72+
let result = validator(this.value, this.schema, this.model);
73+
if (result && isFunction(result.then)) {
74+
result.then(err => {
75+
if (err) {
76+
this.errors = this.errors.concat(err);
77+
}
9778
let isValid = this.errors.length === 0;
9879
this.$emit("validated", isValid, this.errors, this);
99-
}
100-
});
101-
} else {
102-
if (res) addErrors(res);
80+
});
81+
} else if (result) {
82+
results = results.concat(result);
83+
}
10384
}
10485
});
10586
}
10687

107-
if (isFunction(this.schema.onValidated)) {
108-
this.schema.onValidated.call(this, this.model, this.errors, this.schema);
109-
}
88+
let handleErrors = errors => {
89+
let fieldErrors = [];
90+
forEach(errors, err => {
91+
if (isArray(err) && err.length > 0) {
92+
fieldErrors = fieldErrors.concat(err);
93+
} else if (isString(err)) {
94+
fieldErrors.push(err);
95+
}
96+
});
97+
if (isFunction(this.schema.onValidated)) {
98+
this.schema.onValidated.call(this, this.model, fieldErrors, this.schema);
99+
}
110100

111-
let isValid = this.errors.length === 0;
112-
if (!calledParent) this.$emit("validated", isValid, this.errors, this);
101+
let isValid = fieldErrors.length === 0;
102+
if (!calledParent) {
103+
this.$emit("validated", isValid, fieldErrors, this);
104+
}
105+
this.errors = fieldErrors;
106+
return fieldErrors;
107+
};
113108

114-
return this.errors;
109+
if (!validateAsync) {
110+
return handleErrors(results);
111+
}
112+
113+
return Promise.all(results).then(handleErrors);
115114
},
115+
116116
debouncedValidate() {
117117
if (!isFunction(this.debouncedValidateFunc)) {
118118
this.debouncedValidateFunc = debounce(this.validate.bind(this), objGet(this, "$parent.options.validateDebounceTime", 500));
119119
}
120120
this.debouncedValidateFunc();
121121
},
122+
123+
updateModelValue(newValue, oldValue) {
124+
let changed = false;
125+
if (isFunction(this.schema.set)) {
126+
this.schema.set(this.model, newValue);
127+
changed = true;
128+
} else if (this.schema.model) {
129+
this.setModelValueByPath(this.schema.model, newValue);
130+
changed = true;
131+
}
132+
133+
if (changed) {
134+
this.$emit("model-updated", newValue, this.schema.model);
135+
136+
if (isFunction(this.schema.onChanged)) {
137+
this.schema.onChanged.call(this, this.model, newValue, oldValue, this.schema);
138+
}
139+
140+
if (this.$parent.options && this.$parent.options.validateAfterChanged === true) {
141+
if (this.$parent.options.validateDebounceTime > 0) {
142+
this.debouncedValidate();
143+
} else {
144+
this.validate();
145+
}
146+
}
147+
}
148+
},
149+
122150
clearValidationErrors() {
123151
this.errors.splice(0);
124152
},

0 commit comments

Comments
 (0)