forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfieldInput.vue
97 lines (90 loc) · 2.18 KB
/
fieldInput.vue
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
<template lang="jade">
.wrapper
input.form-control(
:type="schema.inputType",
:value="value",
@input="value = $event.target.value",
number="schema.inputType == 'number'"
:disabled="disabled",
:accept="schema.accept",
:alt="schema.alt",
:autocomplete="schema.autocomplete",
:checked="schema.checked",
:dirname="schema.dirname",
:formaction="schema.formaction",
:formenctype="schema.formenctype",
:formmethod="schema.formmethod",
:formnovalidate="schema.formnovalidate",
:formtarget="schema.formtarget",
:height="schema.height",
:list="schema.list",
:max="schema.max",
:maxlength="schema.maxlength",
:min="schema.min",
:multiple="schema.multiple",
:name="schema.inputName",
:pattern="schema.pattern",
:placeholder="schema.placeholder",
:readonly="schema.readonly",
:required="schema.required",
:size="schema.size",
:src="schema.src",
:step="schema.step",
:width="schema.width",
:files="schema.files")
span.helper(v-if="schema.inputType === 'color' || schema.inputType === 'range'") {{ value }}
</template>
<script>
import abstractField from "../abstractField";
import fecha from "fecha";
export default {
mixins: [ abstractField ],
methods: {
formatValueToField(value) {
if (value != null) {
switch(this.schema.inputType){
case "date":
return fecha.format(value, "YYYY-MM-DD");
case "datetime":
return fecha.format(value, "YYYY-MM-DD HH:mm:ss");
case "datetime-local":
return fecha.format(value, "YYYY-MM-DDTHH:mm:ss");
}
}
return value;
},
formatValueToModel(value) {
if (value != null) {
switch (this.schema.inputType){
case "date":
return fecha.parse(value, "YYYY-MM-DD");
case "datetime":
return fecha.parse(value, "YYYY-MM-DD HH:mm:ss");
case "datetime-local":
return fecha.parse(value, "YYYY-MM-DDTHH:mm:ss");
}
}
return value;
}
}
};
</script>
<style lang="sass">
.vue-form-generator .field-input {
.wrapper {
width: 100%;
}
input[type="radio"] {
width: 100%;
}
input[type="color"] {
width: 60px;
}
input[type="range"] {
padding: 0;
}
.helper {
margin: auto 0.5em;
}
}
</style>