Skip to content

Commit

Permalink
Fix force input value refresh when date is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
jtommy committed Sep 1, 2017
1 parent e1d7357 commit 6689c74
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/datepicker/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
return {
dateSelected: this.value,
formattedDateSelected: this.formatValue(this.value),
focusedDateData: {
month: focusedDate.getMonth(),
year: focusedDate.getFullYear()
Expand Down Expand Up @@ -233,6 +232,10 @@
return arrayOfYears.reverse()
},
formattedDateSelected() {
return this.formatValue(this.dateSelected)
},
isFirstMonth() {
if (!this.minDate) return false
const dateToCheck = new Date(this.focusedDateData.year, this.focusedDateData.month)
Expand Down Expand Up @@ -262,7 +265,6 @@
month: currentDate.getMonth(),
year: currentDate.getFullYear()
}
this.formattedDateSelected = this.formatValue(value)
this.$emit('input', value)
if (this.$refs.dropdown) {
this.$refs.dropdown.isActive = false
Expand Down Expand Up @@ -297,6 +299,11 @@
this.dateSelected = date
} else {
this.dateSelected = null
// force refresh when not valid date
this.$nextTick(() => {
// see computed 'formattedDateSelected'
this.$refs.input.$refs.input.value = this.formatValue(this.dateSelected)
})
}
},
Expand Down Expand Up @@ -371,9 +378,6 @@
const date = event.target.value
this.dateSelected = date ? new Date(date) : null
}
},
mounted() {
// this.formattedDateSelected = this.formatValue(this.dateSelected)
}
}
</script>

0 comments on commit 6689c74

Please sign in to comment.