Skip to content

Commit caa4124

Browse files
committed
rename example & improve code
1 parent d2b67e0 commit caa4124

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

dev/multipleforms/app.vue renamed to dev/grouping/app.vue

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template lang="html">
22
<form>
3-
<vue-form-generator :schema="section1" :model="model" :options="formOptions"></vue-form-generator>
4-
<vue-form-generator :schema="section2" :model="model" :options="formOptions"></vue-form-generator>
3+
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
54
<pre>{{ model }}</pre>
65
</form>
76
</template>
@@ -15,12 +14,14 @@ export default {
1514
model: {
1615
name: 'Brian Blessed',
1716
18-
more: "More",
19-
things: "Things",
20-
pref_1: 'blah'
17+
others: {
18+
more: "More",
19+
things: "Things"
20+
},
21+
single: 'blah'
2122
},
2223
23-
section1: {
24+
schema: {
2425
groups:[{
2526
legend: "Contact Details",
2627
fields: [
@@ -44,39 +45,28 @@ export default {
4445
type: "input",
4546
inputType: "text",
4647
label: "More",
47-
model: "more"
48+
model: "others.more"
4849
},
4950
{
5051
type: "input",
5152
inputType: "text",
5253
label: "Things",
53-
model: "things"
54+
model: "others.things"
5455
}
5556
]
5657
}],
5758
fields: [
5859
{
5960
type: "input",
6061
inputType: "text",
61-
label: "Pref 1 (without group)",
62-
model: "pref_1"
63-
}
64-
]
65-
},
66-
67-
section2: {
68-
fields: [
69-
{
70-
type: "input",
71-
inputType: "text",
72-
label: "Pref 1",
73-
model: "pref_1"
62+
label: "Single field (without group)",
63+
model: "single"
7464
}
7565
]
7666
},
7767
7868
formOptions: {
79-
fieldIdPrefix: 'frm1_'
69+
fieldIdPrefix: 'frm1-'
8070
}
8171
}
8272
},

dev/multipleforms/index.html renamed to dev/grouping/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<body>
88
<div class="container-fluid"></div>
99
<div id="app"></div>
10-
<script src="/mforms.js"></script>
10+
<script src="/grouping.js"></script>
1111
</body>
1212
</html>
File renamed without changes.

src/formGenerator.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
div.vue-form-generator(v-if='schema != null')
33
template(v-for='field in fields')
4-
fieldset(v-if='schema != null', :is='tag')
4+
fieldset(:is='tag')
55
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
66
label(v-if="fieldTypeHasLabel(field)", :for="getFieldID(field)")
77
| {{ field.label }}
@@ -15,8 +15,9 @@ div.vue-form-generator(v-if='schema != null')
1515
.hint(v-if='field.hint') {{ field.hint }}
1616
.errors.help-block(v-if='fieldErrors(field).length > 0')
1717
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
18+
1819
template(v-for='group in groups')
19-
fieldset(v-if='schema != null', :is='tag')
20+
fieldset(:is='tag')
2021
legend(v-if='group.legend') {{ group.legend }}
2122
template(v-for='field in group.fields')
2223
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
@@ -151,7 +152,14 @@ div.vue-form-generator(v-if='schema != null')
151152
152153
beforeMount() {
153154
// Add idPrefix to fields if fieldIdPrefix is set
154-
if (this.schema.fields) {
155+
if ("groups" in this.schema) {
156+
for (let group of this.schema.groups) {
157+
for (let field of group.fields) {
158+
field.idPrefix = this.options.fieldIdPrefix || "";
159+
}
160+
}
161+
}
162+
if ("fields" in this.schema) {
155163
for (let field of this.schema.fields) {
156164
field.idPrefix = this.options.fieldIdPrefix || "";
157165
}

webpack.dev.config.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
entry: {
3535
full: path.resolve("dev", "full", "main.js"),
3636
mselect: path.resolve("dev", "multiselect", "main.js"),
37-
mforms: path.resolve("dev", "multipleforms", "main.js"),
37+
grouping: path.resolve("dev", "grouping", "main.js"),
3838
checklist: path.resolve("dev", "checklist", "main.js")
3939
},
4040

@@ -44,14 +44,14 @@ module.exports = {
4444
publicPath: "/"
4545
},
4646

47-
plugins: [
48-
new webpack.DefinePlugin({
49-
"process.env": {
50-
NODE_ENV: JSON.stringify("development"),
51-
FULL_BUNDLE: true
52-
}
53-
}),
54-
],
47+
plugins: [
48+
new webpack.DefinePlugin({
49+
"process.env": {
50+
NODE_ENV: JSON.stringify("development"),
51+
FULL_BUNDLE: true
52+
}
53+
}),
54+
],
5555

5656
module: {
5757
loaders

0 commit comments

Comments
 (0)