Skip to content

Instantly share code, notes, and snippets.

@d-levin
Created May 24, 2017 01:36
Show Gist options
  • Save d-levin/9e13a75be115f76ea7cf934f7924f37a to your computer and use it in GitHub Desktop.
Save d-levin/9e13a75be115f76ea7cf934f7924f37a to your computer and use it in GitHub Desktop.
Generic input component for Vuejs that supports dynamic input type
/**
* Generic input component of type [text] or [number]
*/
export default {
render (createElement) {
return createElement(
'input',
{
'class': {
'has-error': this.hasErrorClass && !this.hasValidClass,
'valid-input': this.hasValidClass
},
staticClass: [ 'full-width' ],
attrs: {
'data-automate-id': this.dataAutomateId,
type: this.type
},
domProps: {
required: true,
value: this.value,
readOnly: this.readOnly,
disabled: this.disabled
},
on: {
blur: evt => this.$emit('blur', evt),
change: evt => this.$emit('change', evt),
click: evt => this.$emit('click', evt),
input: evt => this.$emit('input', evt.target.value)
}
}
)
},
props: {
dataAutomateId: String,
disabled: Boolean,
hasErrorClass: Boolean,
hasValidClass: Boolean,
readOnly: Boolean,
type: {
type: String,
validator (type) {
return type === 'number' || type === 'text'
},
default () {
return 'text'
}
},
value: {
required: true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment