2
2
.wrapper ( v-attributes ="'wrapper'" )
3
3
input.form-control (
4
4
:id ="getFieldID(schema)" ,
5
- :type ="schema. inputType.toLowerCase() " ,
5
+ :type ="inputType" ,
6
6
:value ="value" ,
7
7
@input ="onInput" ,
8
8
@blur ="onBlur" ,
@@ -53,6 +53,16 @@ const DATETIME_FORMATS = {
53
53
54
54
export default {
55
55
mixins: [abstractField],
56
+ computed: {
57
+ inputType () {
58
+ if (this .schema && this .schema .inputType === " datetime" ) {
59
+ // convert "datetime" to "datetime-local" (datetime deprecated in favor of "datetime-local")
60
+ // ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime
61
+ return " datetime-local" ;
62
+ }
63
+ return this .schema .inputType ;
64
+ }
65
+ },
56
66
methods: {
57
67
formatValueToModel (value ) {
58
68
if (value != null ) {
@@ -71,6 +81,15 @@ export default {
71
81
72
82
return value;
73
83
},
84
+ formatValueToField (value ) {
85
+ switch (this .schema .inputType .toLowerCase ()) {
86
+ case " date" :
87
+ case " datetime" :
88
+ case " datetime-local" :
89
+ return this .formatDatetimeValueToField (value);
90
+ }
91
+ return value;
92
+ },
74
93
formatDatetimeToModel (newValue , oldValue ) {
75
94
let defaultFormat = DATETIME_FORMATS [this .schema .inputType .toLowerCase ()];
76
95
let m = fecha .parse (newValue, defaultFormat);
@@ -83,6 +102,17 @@ export default {
83
102
}
84
103
this .updateModelValue (newValue, oldValue);
85
104
},
105
+ formatDatetimeValueToField (value ) {
106
+ let defaultFormat = DATETIME_FORMATS [this .schema .inputType .toLowerCase ()];
107
+ let m = value;
108
+ if (! isNumber (value)) {
109
+ m = fecha .parse (value, defaultFormat);
110
+ }
111
+ if (m !== false ) {
112
+ return fecha .format (m, defaultFormat);
113
+ }
114
+ return value;
115
+ },
86
116
formatNumberToModel (newValue , oldValue ) {
87
117
if (! isNumber (newValue)) {
88
118
newValue = NaN ;
0 commit comments