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

Commit

Permalink
Add form-generator dev example
Browse files Browse the repository at this point in the history
  • Loading branch information
cristijora committed Aug 28, 2017
1 parent 899b8ab commit ce4aaba
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 0 deletions.
162 changes: 162 additions & 0 deletions dev-example/FormGeneratorRoute.vue
@@ -0,0 +1,162 @@
<template>
<div>
<form-wizard @on-complete="onComplete"
color="gray"
error-color="#a94442">
<tab-content title="Personal details"
icon="ti-user" :before-change="validateFirstTab">
<vue-form-generator :model="model"
:schema="firstTabSchema"
:options="formOptions"
ref="firstTabForm">

</vue-form-generator>
</tab-content>
<tab-content title="Additional Info"
icon="ti-settings" :before-change="validateSecondTab">
<vue-form-generator :model="model"
:schema="secondTabSchema"
:options="formOptions"
ref="secondTabForm">
</vue-form-generator>

</tab-content>
<tab-content title="Last step"
icon="ti-check">
<h4>Your json is ready!</h4>
</tab-content>
</form-wizard>
</div>
</template>
<script>
import VueFormGenerator from 'vue-form-generator'
import 'vue-form-generator/dist/vfg-core.css'
import 'bootstrap/dist/css/bootstrap.css'
import Vue from "vue";
Vue.use(VueFormGenerator)
export default {
data() {
return {
model: {
firstName: '',
lastName: '',
email: '',
streetName: '',
streetNumber: '',
city: '',
country: ''
},
formOptions: {
validationErrorClass: "has-error",
validationSuccessClass: "has-success",
validateAfterChanged: true
},
firstTabSchema: {
fields: [{
type: "input",
inputType: "text",
label: "First name",
model: "firstName",
required: true,
validator: VueFormGenerator.validators.string,
styleClasses: 'col-xs-6'
},
{
type: "input",
inputType: "text",
label: "Last name",
model: "lastName",
required: true,
validator: VueFormGenerator.validators.string,
styleClasses: 'col-xs-6'
},
{
type: "input",
inputType: "text",
label: "Email",
model: "email",
required: true,
validator: VueFormGenerator.validators.email,
styleClasses: 'col-xs-12'
}
]
},
secondTabSchema: {
fields: [
{
type: "input",
inputType: "text",
label: "Street name",
model: "streetName",
required: true,
validator: VueFormGenerator.validators.string,
styleClasses: 'col-xs-9'
},
{
type: "input",
inputType: "text",
label: "Street number",
model: "streetNumber",
required: true,
validator: VueFormGenerator.validators.string,
styleClasses: 'col-xs-3'
},
{
type: "input",
inputType: "text",
label: "City",
model: "city",
required: true,
validator: VueFormGenerator.validators.string,
styleClasses: 'col-xs-6'
},
{
type: "select",
label: "Country",
model: "country",
required: true,
validator: VueFormGenerator.validators.string,
values: ['United Kingdom', 'Romania', 'Germany'],
styleClasses: 'col-xs-6'
},
]
}
}
},
methods: {
onComplete() {
alert('Yay. Done!');
},
validateFirstTab() {
return this.$refs.firstTabForm.validate();
},
validateSecondTab: function () {
return this.$refs.secondTabForm.validate();
},
prettyJSON(json) {
if (json) {
json = JSON.stringify(json, undefined, 4);
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
}
}
}
</script>
<style>
</style>
2 changes: 2 additions & 0 deletions dev-example/main.js
Expand Up @@ -5,6 +5,7 @@ import VueRouter from 'vue-router'
import App from './App.vue'
import FormWizard from '../src/index'
import WizardRoute from './WizardRoute.vue'
import FormGeneratorRoute from './FormGeneratorRoute.vue'
import TestRoute from './TestRoute.vue'

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

]
})
Expand Down

0 comments on commit ce4aaba

Please sign in to comment.