Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit ce4aaba

Browse files
committed
Add form-generator dev example
1 parent 899b8ab commit ce4aaba

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

Diff for: dev-example/FormGeneratorRoute.vue

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<template>
2+
<div>
3+
<form-wizard @on-complete="onComplete"
4+
color="gray"
5+
error-color="#a94442">
6+
<tab-content title="Personal details"
7+
icon="ti-user" :before-change="validateFirstTab">
8+
<vue-form-generator :model="model"
9+
:schema="firstTabSchema"
10+
:options="formOptions"
11+
ref="firstTabForm">
12+
13+
</vue-form-generator>
14+
</tab-content>
15+
<tab-content title="Additional Info"
16+
icon="ti-settings" :before-change="validateSecondTab">
17+
<vue-form-generator :model="model"
18+
:schema="secondTabSchema"
19+
:options="formOptions"
20+
ref="secondTabForm">
21+
</vue-form-generator>
22+
23+
</tab-content>
24+
<tab-content title="Last step"
25+
icon="ti-check">
26+
<h4>Your json is ready!</h4>
27+
</tab-content>
28+
</form-wizard>
29+
</div>
30+
</template>
31+
<script>
32+
import VueFormGenerator from 'vue-form-generator'
33+
import 'vue-form-generator/dist/vfg-core.css'
34+
import 'bootstrap/dist/css/bootstrap.css'
35+
import Vue from "vue";
36+
Vue.use(VueFormGenerator)
37+
export default {
38+
data() {
39+
return {
40+
model: {
41+
firstName: '',
42+
lastName: '',
43+
email: '',
44+
streetName: '',
45+
streetNumber: '',
46+
city: '',
47+
country: ''
48+
},
49+
formOptions: {
50+
validationErrorClass: "has-error",
51+
validationSuccessClass: "has-success",
52+
validateAfterChanged: true
53+
},
54+
firstTabSchema: {
55+
fields: [{
56+
type: "input",
57+
inputType: "text",
58+
label: "First name",
59+
model: "firstName",
60+
required: true,
61+
validator: VueFormGenerator.validators.string,
62+
styleClasses: 'col-xs-6'
63+
},
64+
{
65+
type: "input",
66+
inputType: "text",
67+
label: "Last name",
68+
model: "lastName",
69+
required: true,
70+
validator: VueFormGenerator.validators.string,
71+
styleClasses: 'col-xs-6'
72+
},
73+
{
74+
type: "input",
75+
inputType: "text",
76+
label: "Email",
77+
model: "email",
78+
required: true,
79+
validator: VueFormGenerator.validators.email,
80+
styleClasses: 'col-xs-12'
81+
}
82+
]
83+
},
84+
secondTabSchema: {
85+
fields: [
86+
{
87+
type: "input",
88+
inputType: "text",
89+
label: "Street name",
90+
model: "streetName",
91+
required: true,
92+
validator: VueFormGenerator.validators.string,
93+
styleClasses: 'col-xs-9'
94+
},
95+
{
96+
type: "input",
97+
inputType: "text",
98+
label: "Street number",
99+
model: "streetNumber",
100+
required: true,
101+
validator: VueFormGenerator.validators.string,
102+
styleClasses: 'col-xs-3'
103+
},
104+
{
105+
type: "input",
106+
inputType: "text",
107+
label: "City",
108+
model: "city",
109+
required: true,
110+
validator: VueFormGenerator.validators.string,
111+
styleClasses: 'col-xs-6'
112+
},
113+
{
114+
type: "select",
115+
label: "Country",
116+
model: "country",
117+
required: true,
118+
validator: VueFormGenerator.validators.string,
119+
values: ['United Kingdom', 'Romania', 'Germany'],
120+
styleClasses: 'col-xs-6'
121+
},
122+
]
123+
}
124+
}
125+
},
126+
methods: {
127+
onComplete() {
128+
alert('Yay. Done!');
129+
},
130+
validateFirstTab() {
131+
return this.$refs.firstTabForm.validate();
132+
},
133+
validateSecondTab: function () {
134+
return this.$refs.secondTabForm.validate();
135+
},
136+
137+
prettyJSON(json) {
138+
if (json) {
139+
json = JSON.stringify(json, undefined, 4);
140+
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
141+
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
142+
var cls = 'number';
143+
if (/^"/.test(match)) {
144+
if (/:$/.test(match)) {
145+
cls = 'key';
146+
} else {
147+
cls = 'string';
148+
}
149+
} else if (/true|false/.test(match)) {
150+
cls = 'boolean';
151+
} else if (/null/.test(match)) {
152+
cls = 'null';
153+
}
154+
return '<span class="' + cls + '">' + match + '</span>';
155+
});
156+
}
157+
}
158+
}
159+
}
160+
</script>
161+
<style>
162+
</style>

Diff for: dev-example/main.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import VueRouter from 'vue-router'
55
import App from './App.vue'
66
import FormWizard from '../src/index'
77
import WizardRoute from './WizardRoute.vue'
8+
import FormGeneratorRoute from './FormGeneratorRoute.vue'
89
import TestRoute from './TestRoute.vue'
910

1011
const First = {template: '<div>First page</div>'}
@@ -23,6 +24,7 @@ const router = new VueRouter({
2324
]
2425
},
2526
{path: '/test', component: TestRoute},
27+
{path: '/form-generator', component: FormGeneratorRoute},
2628

2729
]
2830
})

0 commit comments

Comments
 (0)