pingcrm/resources/js/Shared/TextInput.vue

43 lines
928 B
Vue
Raw Normal View History

2019-03-18 08:53:00 -03:00
<template>
<div>
<label v-if="label" class="form-label" :for="id">{{ label }}:</label>
<input :id="id" ref="input" v-bind="$attrs" class="form-input" :class="{ error: errors.length }" :type="type" :value="value" @input="$emit('input', $event.target.value)">
<div v-if="errors.length" class="form-error">{{ errors[0] }}</div>
2019-03-18 08:53:00 -03:00
</div>
</template>
<script>
export default {
inheritAttrs: false,
props: {
id: {
type: String,
default() {
return `text-input-${this._uid}`
},
},
type: {
type: String,
default: 'text',
},
value: String,
label: String,
errors: {
type: Array,
default: () => [],
},
2019-03-18 08:53:00 -03:00
},
methods: {
focus() {
this.$refs.input.focus()
},
select() {
this.$refs.input.select()
},
setSelectionRange(start, end) {
this.$refs.input.setSelectionRange(start, end)
},
},
}
</script>