vuetify-datetime-picker icon indicating copy to clipboard operation
vuetify-datetime-picker copied to clipboard

Setting datetime model to null does not reset text field.

Open alperkarahisar opened this issue 4 years ago • 3 comments

Changing init method to this solved the problem.

init() {
  if (!this.datetime) {
    this.resetPicker()
    this.date = DEFAULT_DATE
    this.time = DEFAULT_TIME
    return
  }
  let initDateTime
  if (this.datetime instanceof Date) {
    initDateTime = this.datetime
  } else if (typeof this.datetime === 'string' || this.datetime instanceof String) {
    // see https://stackoverflow.com/a/9436948
    initDateTime = parse(this.datetime, this.dateTimeFormat, new Date())
  }
  this.date = format(initDateTime, DEFAULT_DATE_FORMAT)
  this.time = format(initDateTime, DEFAULT_TIME_FORMAT)
},

alperkarahisar avatar Jan 27 '21 10:01 alperkarahisar

Hi,

Nice component for Date Time, I am suffering from this exact same problem.

Any plans to push this update anytime soon to npm repo ?

I am running 2.1.1 and it is not in there ...

Thanks

Matt-Texier avatar Mar 31 '21 18:03 Matt-Texier

me too - any suggested idea's on this?

Moxie1776 avatar Jun 07 '21 17:06 Moxie1776

I was able to workaround this creating a ref to the element and calling clearHandler() method when I want the field to be reseted

<v-datetime-picker v-model="myDateTime" ref="myInput" />
//...
watch: {
   myDateTime (val) {
      if (!val) {
         this.$refs.myInput.clearHandler()
      }
   }
}
//...

I know this isn't the ideal solution, but I'm using this when a fix is not provided

raphacmartin avatar Jun 24 '21 14:06 raphacmartin