Skip to content

Instantly share code, notes, and snippets.

@diverted247
Created December 7, 2017 16:15
Show Gist options
  • Save diverted247/60a90cac17291f1fdf05e96bd50c13cc to your computer and use it in GitHub Desktop.
Save diverted247/60a90cac17291f1fdf05e96bd50c13cc to your computer and use it in GitHub Desktop.
Vue Component Wrapping <input>
Vue.component( 'inputtext' , {
template:'<input type="text" :value="value" @input="input($event.target.value)" @change="change" @keyup="keyup" @keypress="keypress" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" >',
props:['value'],
methods:{
input( newInput ){
this.$emit('input', newInput);
},
change(){
//console.log( 'change: ' + this.value );
if( this.$el.maxlength && this.$el.value.length > this.$el.maxlength ){
this.$el.value = this.$el.value.slice( 0 , this.$el.maxlength );
}
},
keyup(){
//console.log( 'keyup: ' + this.value );
if( this.$el.maxlength && this.$el.value.length > this.$el.maxlength ){
this.$el.value = this.$el.value.slice( 0 , this.$el.maxlength );
}
},
keypress(){
//console.log( 'keypress: ' + this.value );
if( this.$el.maxlength && this.$el.value.length >= this.$el.maxlength ){
return false;
}
return true;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment