Skip to content

Commit

Permalink
fix(datepicker): Set typed date to null if zero length
Browse files Browse the repository at this point in the history
  • Loading branch information
mst101 committed Aug 18, 2021
1 parent 1a1d3aa commit e483f0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export default {
return this.inputClass
},
formattedDate() {
if (!this.selectedDate) {
return null
}
return typeof this.format === 'function'
? this.format(new Date(this.selectedDate))
: this.utils.formatDate(
Expand Down Expand Up @@ -205,6 +209,11 @@ export default {
* Parses a typed date and submits it, if valid
*/
handleKeyup() {
if (this.input.value === '') {
this.$emit('typed-date', null)
return
}
this.parsedDate = Date.parse(
this.utils.parseDate(
this.input.value,
Expand Down
7 changes: 6 additions & 1 deletion src/components/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export default {
* @param {Date} date
*/
handleTypedDate(date) {
this.selectDate(date.valueOf())
this.selectDate(date ? date.valueOf() : null)
},
/**
* Focus the relevant element when the view changes
Expand Down Expand Up @@ -530,6 +530,11 @@ export default {
* @param {Number} timestamp
*/
selectDate(timestamp) {
if (!timestamp) {
this.selectedDate = null
return
}
const date = new Date(timestamp)
this.selectedDate = date
this.setPageDate(date)
Expand Down

0 comments on commit e483f0d

Please sign in to comment.