22.wrapper ( v-attributes ="'wrapper'" )
33 input.form-control (
44 :id ="getFieldID(schema)" ,
5- :type ="schema. inputType.toLowerCase() " ,
5+ :type ="inputType" ,
66 :value ="value" ,
77 @input ="onInput" ,
88 @blur ="onBlur" ,
@@ -53,6 +53,16 @@ const DATETIME_FORMATS = {
5353
5454export default {
5555 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+ },
5666 methods: {
5767 formatValueToModel (value ) {
5868 if (value != null ) {
@@ -71,6 +81,15 @@ export default {
7181
7282 return value;
7383 },
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+ },
7493 formatDatetimeToModel (newValue , oldValue ) {
7594 let defaultFormat = DATETIME_FORMATS [this .schema .inputType .toLowerCase ()];
7695 let m = fecha .parse (newValue, defaultFormat);
@@ -83,6 +102,17 @@ export default {
83102 }
84103 this .updateModelValue (newValue, oldValue);
85104 },
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+ },
86116 formatNumberToModel (newValue , oldValue ) {
87117 if (! isNumber (newValue)) {
88118 newValue = NaN ;
0 commit comments