question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Value input for date picker

See original GitHub issue

Right now v-model is not a part of the docs for the date picker. So it is a little confusing what types of dates you can set the value too. I looked at the source code to see if that helped. It appears that the value can be falsy a Date object or a date string, but not epoch time (which usually seems like one of the best ways to store date information).

Related to this is if you use date-format function to convert the value to a non-recognizable date format then that value gets passed back in through v-model which results in undefined input. If you use computed values on the value then you can circumvent this problem, but then it seems pointless to have a date formatting option and it means you have to jump through extra hoops so that, for example, your input isn’t tied directly to the date-picker. One suggestion would be I’ve seen some other date-pickers that offer a formatted output property separate from the original format. Perhaps someone else has a better suggestion on the best way to deal with this.

Also in looking at the source code I ran into what appears to be an error https://github.com/vuetifyjs/vuetify/blob/master/src/components/pickers/DatePicker.js on line 79

if (!isNaN(this.value) && this.value.indexOf(':') !== -1) return new Date(this.value)

The first boolean statement resolves to true if the value is actually a number, but then you are trying to use indexOf which is a string method. I’m not sure if maybe this is supposed to accept numbers (e.g. epoch time) or if it is actually just wanting date strings.

Summary

  1. Add v-model to the API docs
  2. Add epoch time to one of the accepted values
  3. Look into maybe a better way to handle formatted dates
  4. Correct the error on line 79

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
j-maascommented, Feb 21, 2018

Would it be possible to reflect this restriction in the documentation? A sentence like “The v-model accepts only strings in the YYYY-MM-DD format.” would clear things up a lot.

Thanks for the swift reply! 😃

2reactions
adearicommented, Mar 17, 2018

This can help for format dd/mm/yyyy https://codepen.io/adeari/pen/ZxpXbQ?&editors=101

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="date"> - HTML: HyperText Markup Language
Value. A string representing the date entered in the input. · Additional attributes. The attributes common to all <input> elements apply to the ......
Read more >
How to set default value to the input[type="date"] [duplicate]
A possible solution: document.getElementById("yourDatePicker").valueAsDate = new Date();.
Read more >
HTML DOM Input Date value Property - W3Schools
The value property sets or returns the value of the value attribute of a date field. The value attribute specifies a date for...
Read more >
HTML | DOM Input Date value Property - GeeksforGeeks
The Input Date value property is used for setting or returning the value of the value attribute of a date field. The Input...
Read more >
How to initialize the value for Input Date Picker component
For the date pickers with range type , how to set the default values? See the code pen, the "value" property works for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found