Skip to content

Commit 613e831

Browse files
committed
[FEATURE] Groups
* Add support for schema.groups, schema.groups legend & field id prefixes * Add support for grouping fields. You still can to put fields as always in combination with groups. * Add support for an optional legend for each group/fieldset. Expects the schema to look something like this: ``` section1: { groups:[{ legend: "Contact Details", fields: [ { type: "input", inputType: "text", label: "Name", model: "name" }, { type: "input", inputType: "email", label: "Email", model: "email" } ] },{ legend: "Other Details", fields: [ { type: "input", inputType: "text", label: "More", model: "more" }, { type: "input", inputType: "text", label: "Things", model: "things" } ] }] }, ``` * Add support for field id prefixes, at the form level. So you can add a `fieldIdPrefix: 'prefix_here_'` to your `formOptions` and this will be prepended to _all_ field id's. Based on phemisystems@a6165c8 @dflock @phemisystems
1 parent a6165c8 commit 613e831

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

dev/multipleforms/app.vue

+34-15
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,40 @@ export default {
1818
},
1919
2020
section1: {
21-
legend: "Contact Details",
22-
fields: [
23-
{
24-
type: "input",
25-
inputType: "text",
26-
label: "Name",
27-
model: "name"
28-
},
29-
{
30-
type: "input",
31-
inputType: "email",
32-
label: "Email",
33-
model: "email"
34-
}
35-
]
21+
groups:[{
22+
legend: "Contact Details",
23+
fields: [
24+
{
25+
type: "input",
26+
inputType: "text",
27+
label: "Name",
28+
model: "name"
29+
},
30+
{
31+
type: "input",
32+
inputType: "email",
33+
label: "Email",
34+
model: "email"
35+
}
36+
]
37+
},{
38+
legend: "Other Details",
39+
fields: [
40+
{
41+
type: "input",
42+
inputType: "text",
43+
label: "More",
44+
model: "more"
45+
},
46+
{
47+
type: "input",
48+
inputType: "text",
49+
label: "Things",
50+
model: "things"
51+
}
52+
]
53+
}]
54+
3655
},
3756
3857
section2: {

src/formGenerator.vue

+38-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template lang="pug">
22
div
33
fieldset.vue-form-generator(v-if='schema != null', :is='tag')
4-
legend(v-if='schema.legend') {{ schema.legend }}
5-
template(v-for='field in fields')
4+
template(v-for='field in fields' v-if='fields')
65
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
76
label(v-if="fieldTypeHasLabel(field)", :for="getFieldID(field)")
87
| {{ field.label }}
@@ -16,6 +15,22 @@ div
1615
.hint(v-if='field.hint') {{ field.hint }}
1716
.errors.help-block(v-if='fieldErrors(field).length > 0')
1817
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
18+
template(v-for='group in groups' v-if='groups')
19+
legend(v-if='group.legend') {{ group.legend }}
20+
template(v-for='field in group.fields')
21+
.form-group(v-if='fieldVisible(field)', :class='getFieldRowClasses(field)')
22+
label(v-if="fieldTypeHasLabel(field)", :for="getFieldID(field)")
23+
| {{ field.label }}
24+
span.help(v-if='field.help')
25+
i.icon
26+
.helpText(v-html='field.help')
27+
.field-wrap
28+
component(:is='getFieldType(field)', :disabled='fieldDisabled(field)', :model='model', :schema.sync='field', @model-updated='modelUpdated', @validated="onFieldValidated")
29+
.buttons(v-if='buttonVisibility(field)')
30+
button(v-for='btn in field.buttons', @click='buttonClickHandler(btn, field)', :class='btn.classes') {{ btn.label }}
31+
.hint(v-if='field.hint') {{ field.hint }}
32+
.errors.help-block(v-if='fieldErrors(field).length > 0')
33+
span(v-for='(error, index) in fieldErrors(field)', track-by='index') {{ error }}
1934
</template>
2035

2136
<script>
@@ -92,17 +107,27 @@ div
92107
},
93108
94109
computed: {
95-
fields() {
96-
let res = [];
97-
if (this.schema) {
98-
each(this.schema.fields, (field) => {
99-
if (!this.multiple || field.multi === true)
100-
res.push(field);
101-
});
102-
}
103-
104-
return res;
105-
}
110+
fields() {
111+
let res = [];
112+
if (this.schema && this.schema.fields) {
113+
each(this.schema.fields, (field) => {
114+
if (!this.multiple || field.multi === true)
115+
res.push(field);
116+
});
117+
}
118+
119+
return res;
120+
},
121+
groups() {
122+
let res = [];
123+
if (this.schema && this.schema.groups) {
124+
each(this.schema.groups, (group) => {
125+
res.push(group);
126+
});
127+
}
128+
129+
return res;
130+
}
106131
},
107132
108133
watch: {

0 commit comments

Comments
 (0)