Skip to content

Commit

Permalink
fix(VTimePicker): emit proper value in change event
Browse files Browse the repository at this point in the history
fixes #5266
  • Loading branch information
jacekkarczmarczyk committed Dec 1, 2018
1 parent 4181ccb commit ad3a948
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/vuetify/src/components/VTimePicker/VTimePicker.js
Expand Up @@ -46,6 +46,9 @@ export default {
inputHour: null,
inputMinute: null,
inputSecond: null,
lazyInputHour: null,
lazyInputMinute: null,
lazyInputSecond: null,
period: 'am',
selecting: selectingTimes.hour
}
Expand Down Expand Up @@ -159,10 +162,7 @@ export default {
this.inputHour = null
this.inputMinute = null
this.inputSecond = null
return
}

if (value instanceof Date) {
} else if (value instanceof Date) {
this.inputHour = value.getHours()
this.inputMinute = value.getMinutes()
this.inputSecond = value.getSeconds()
Expand All @@ -174,7 +174,7 @@ export default {
this.inputSecond = parseInt(second || 0, 10)
}

this.period = this.inputHour < 12 ? 'am' : 'pm'
this.period = (this.inputHour == null || this.inputHour < 12) ? 'am' : 'pm'
},
convert24to12 (hour) {
return hour ? ((hour - 1) % 12 + 1) : 12
Expand All @@ -193,11 +193,22 @@ export default {
this.emitValue()
},
onChange () {
if (this.selecting === (this.useSeconds ? selectingTimes.second : selectingTimes.minute)) {
this.$emit('change', this.value)
// this.selecting = selectingTimes.hour
} else {
this.selecting++
if (this.selecting === selectingTimes.hour) {
this.selecting = selectingTimes.minute
} else if (this.useSeconds && this.selecting === selectingTimes.minute) {
this.selecting = selectingTimes.second
}

if (this.inputHour !== this.lazyInputHour ||
this.inputMinute !== this.lazyInputMinute ||
(this.useSeconds && this.inputSecond !== this.lazyInputSecond)
) {
if (this.inputHour != null && this.inputMinute != null && (!this.useSeconds || this.inputSecond != null)) {
this.lazyInputHour = this.inputHour
this.lazyInputMinute = this.inputMinute
this.useSeconds && (this.lazyInputSecond = this.inputSecond)
this.$emit('change', `${pad(this.inputHour)}:${pad(this.inputMinute)}` + (this.useSeconds ? `:${pad(this.inputSecond)}` : ''))
}
}
},
firstAllowed (type, value) {
Expand Down

0 comments on commit ad3a948

Please sign in to comment.