Skip to content

Commit 01e12df

Browse files
authored
Merge pull request #4 from kevinkosterr/master
Release 1.4.2
2 parents 340624d + 251308a commit 01e12df

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/fields/core/fieldInput.vue

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,30 @@ export default {
136136
return value
137137
},
138138
formatDatetimeToModel(newValue, oldValue) {
139-
let defaultFormat = DATETIME_FORMATS[this.schema.inputType.toLowerCase()]
140-
let m = fecha.parse(newValue, defaultFormat)
141-
if (m !== false) {
142-
if (this.schema.format) {
143-
newValue = fecha.format(m, this.schema.format)
144-
} else {
145-
newValue = m.valueOf()
139+
const format = DATETIME_FORMATS[this.schema.inputType.toLowerCase()]
140+
if (newValue) {
141+
let m = fecha.parse(newValue, format)
142+
if (m !== false) {
143+
if (this.schema.format) {
144+
newValue = fecha.format(m, this.schema.format)
145+
} else {
146+
newValue = m.valueOf()
147+
}
146148
}
147149
}
148150
this.updateModelValue(newValue, oldValue)
149151
},
150152
formatDatetimeValueToField(value) {
151-
if(value === null || undefined === value) {
152-
return null
153-
}
153+
if (!value) return null
154154
155-
let defaultFormat = DATETIME_FORMATS[this.schema.inputType.toLowerCase()]
155+
const format = DATETIME_FORMATS[this.schema.inputType.toLowerCase()]
156156
let m = value
157+
157158
if(!isNumber(value)) {
158-
m = fecha.parse(value, defaultFormat)
159+
m = fecha.parse(value, format)
159160
}
160-
if(m !== false) {
161-
return fecha.format(m, defaultFormat)
162-
}
163-
return value
161+
162+
return m !== false ? fecha.format(m, format) : value
164163
},
165164
formatNumberToModel(newValue, oldValue) {
166165
if (!isNumber(newValue)) {

0 commit comments

Comments
 (0)