Skip to content

Commit

Permalink
use keypress to prevent typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Kassel committed May 8, 2018
1 parent 999fc5d commit 5b588ca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:disabled="disabled"
:required="required"
@click="showCalendar"
@keypress="allowTyping"
@keyup="parseTypedDate"
@blur="inputBlurred">
<!-- Clear Button -->
Expand Down Expand Up @@ -89,8 +90,20 @@ export default {
showCalendar () {
this.$emit('showCalendar')
},
/**
* Prevent typing if not typeable
* @param {Event} event
*/
allowTyping (event) {
if (!this.typeable) {
event.preventDefault()
return false
}
return true
},
/**
* Attempt to parse a typed date
* @param {Event} event
*/
parseTypedDate (event) {
// close calendar if escape or enter are pressed
Expand All @@ -103,11 +116,7 @@ export default {
this.$emit('closeCalendar')
return false
}
// prevent typing if not typeable
if (!this.typeable) {
event.preventDefault()
return false
}
const typedDate = Date.parse(this.input.value)
if (!isNaN(typedDate)) {
this.typedDate = this.input.value
Expand Down

0 comments on commit 5b588ca

Please sign in to comment.