Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting datetime model to null does not reset text field. #93

Open
alperkarahisar opened this issue Jan 27, 2021 · 3 comments
Open

Setting datetime model to null does not reset text field. #93

alperkarahisar opened this issue Jan 27, 2021 · 3 comments

Comments

@alperkarahisar
Copy link

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)
},
caesarleong added a commit to caesarleong/vuetify-datetime-picker that referenced this issue Mar 3, 2021
@Matt-Texier
Copy link

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

@Moxie1776
Copy link

me too - any suggested idea's on this?

@raphacmartin
Copy link

raphacmartin commented Jun 24, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants