forked from matfish2/vue-form-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
163 lines (147 loc) · 4.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import merge from 'merge'
import formTemplate from './lib/templates/form.jsx'
import opts from './lib/computed/opts'
import statusBar from './lib/components/status-bar'
import Submit from './lib/components/submit'
import labelClass from './lib/computed/label-class'
import fieldClass from './lib/computed/field-class'
import hasErrors from './lib/computed/has-errors'
import submit from './lib/methods/submit'
import formData from './lib/methods/form-data'
import getField from './lib/methods/get-field'
import showAllErrors from './lib/methods/show-all-errors'
import reinitForm from './lib/methods/reinit-form'
import registerInterfieldsRules from './lib/methods/register-interfields-rules'
import registerTriggers from './lib/methods/register-triggers'
import childrenOf from './lib/methods/children-of'
import getStatusBar from './lib/methods/get-status-bar'
import dispatch from './lib/methods/dispatch'
import text from './lib/components/fields/text'
import password from './lib/components/fields/password'
import fields from './lib/templates/fields'
import Email from './lib/components/fields/email'
import Number from './lib/components/fields/number'
import File from './lib/components/fields/file'
import TextArea from './lib/components/fields/textarea'
import Select from './lib/components/fields/select'
import ButtonsList from './lib/components/fields/buttons-list'
import Date from './lib/components/fields/date'
import Checkbox from './lib/components/fields/checkbox'
const install = function(Vue, globalOptions, customFields) {
customFields = customFields?customFields:{};
var vfForm = {
render: formTemplate,
props: {
name:{
type:String,
required:false
},
client:{
type:Boolean,
required:false,
default: false
},
ajax: {
type: Boolean,
required: false,
default: false
},
action: {
type: String
},
method: {
type: String,
required:false,
default: 'POST'
},
validation: {
type: Object,
required:false,
default: function() {
return {
}
}
},
triggers:{
type: Object,
required:false,
default: function() {
return {
}
}
},
options:{
type: Object,
required:false,
default: function() {
return {
}
}
}
},
created: function() {
if (!this.ajax && !this.client) {
var payload = this.options.additionalPayload;
for (var key in payload) {
this.additionalValues.push({name:key,value:payload[key]});
}
}
this.registerInterfieldsRules();
this.registerTriggers();
},
data: function() {
return {
globalOptions: globalOptions?globalOptions:{},
templates: merge.recursive(fields, customFields),
isForm: true,
fields:[],
additionalValues:[],
errors:[],
relatedFields:{},
triggeredFields:{},
sending:false
}
},
computed: {
labelClass,
fieldClass,
hasErrors,
server: () => {
return !this.ajax && !this.client;
},
opts,
pristine: function() {
return this.fields.length==0;
}
},
methods: {
submit,
formData,
getField,
showAllErrors,
reinitForm,
registerInterfieldsRules,
registerTriggers,
childrenOf,
getStatusBar,
dispatch,
getOptions: opts
}
}
Vue.component('vf-form',vfForm);
Vue.component('vf-text',text());
Vue.component('vf-email',Email());
Vue.component('vf-number', Number());
Vue.component('vf-password',password());
Vue.component('vf-file',File());
Vue.component('vf-textarea',TextArea());
Vue.component('vf-select',Select());
Vue.component('vf-buttons-list', ButtonsList());
Vue.component('vf-date',Date());
Vue.component('vf-checkbox',Checkbox());
Vue.component('vf-status-bar', statusBar);
Vue.component('vf-submit', Submit)
}
export default {
install
}