Skip to content

Commit

Permalink
rename example & improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 25, 2017
1 parent d2b67e0 commit caa4124
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
34 changes: 12 additions & 22 deletions dev/multipleforms/app.vue → dev/grouping/app.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template lang="html">
<form>
<vue-form-generator :schema="section1" :model="model" :options="formOptions"></vue-form-generator>
<vue-form-generator :schema="section2" :model="model" :options="formOptions"></vue-form-generator>
<vue-form-generator :schema="schema" :model="model" :options="formOptions"></vue-form-generator>
<pre>{{ model }}</pre>
</form>
</template>
Expand All @@ -15,12 +14,14 @@ export default {
model: {
name: 'Brian Blessed',
email: "[email protected]",
more: "More",
things: "Things",
pref_1: 'blah'
others: {
more: "More",
things: "Things"
},
single: 'blah'
},
section1: {
schema: {
groups:[{
legend: "Contact Details",
fields: [
Expand All @@ -44,39 +45,28 @@ export default {
type: "input",
inputType: "text",
label: "More",
model: "more"
model: "others.more"
},
{
type: "input",
inputType: "text",
label: "Things",
model: "things"
model: "others.things"
}
]
}],
fields: [
{
type: "input",
inputType: "text",
label: "Pref 1 (without group)",
model: "pref_1"
}
]
},
section2: {
fields: [
{
type: "input",
inputType: "text",
label: "Pref 1",
model: "pref_1"
label: "Single field (without group)",
model: "single"
}
]
},
formOptions: {
fieldIdPrefix: 'frm1_'
fieldIdPrefix: 'frm1-'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion dev/multipleforms/index.html → dev/grouping/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<body>
<div class="container-fluid"></div>
<div id="app"></div>
<script src="/mforms.js"></script>
<script src="/grouping.js"></script>
</body>
</html>
File renamed without changes.
14 changes: 11 additions & 3 deletions src/formGenerator.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
div.vue-form-generator(v-if='schema != null')
template(v-for='field in fields')
fieldset(v-if='schema != null', :is='tag')
fieldset(:is='tag')
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
label(v-if="fieldTypeHasLabel(field)", :for="getFieldID(field)")
| {{ field.label }}
Expand All @@ -15,8 +15,9 @@ div.vue-form-generator(v-if='schema != null')
.hint(v-if='field.hint') {{ field.hint }}
.errors.help-block(v-if='fieldErrors(field).length > 0')
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}

template(v-for='group in groups')
fieldset(v-if='schema != null', :is='tag')
fieldset(:is='tag')
legend(v-if='group.legend') {{ group.legend }}
template(v-for='field in group.fields')
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
Expand Down Expand Up @@ -151,7 +152,14 @@ div.vue-form-generator(v-if='schema != null')
beforeMount() {
// Add idPrefix to fields if fieldIdPrefix is set
if (this.schema.fields) {
if ("groups" in this.schema) {
for (let group of this.schema.groups) {
for (let field of group.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
}
}
if ("fields" in this.schema) {
for (let field of this.schema.fields) {
field.idPrefix = this.options.fieldIdPrefix || "";
}
Expand Down
18 changes: 9 additions & 9 deletions webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
entry: {
full: path.resolve("dev", "full", "main.js"),
mselect: path.resolve("dev", "multiselect", "main.js"),
mforms: path.resolve("dev", "multipleforms", "main.js"),
grouping: path.resolve("dev", "grouping", "main.js"),
checklist: path.resolve("dev", "checklist", "main.js")
},

Expand All @@ -44,14 +44,14 @@ module.exports = {
publicPath: "/"
},

plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development"),
FULL_BUNDLE: true
}
}),
],
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development"),
FULL_BUNDLE: true
}
}),
],

module: {
loaders
Expand Down

0 comments on commit caa4124

Please sign in to comment.