pingcrm/resources/js/Shared/SelectInput.vue

45 lines
849 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>
2020-09-08 17:14:52 -03:00
<select :id="id" ref="input" v-model="selected" v-bind="$attrs" class="form-select" :class="{ error: error }">
2019-03-18 08:53:00 -03:00
<slot />
</select>
2020-09-08 17:14:52 -03:00
<div v-if="error" class="form-error">{{ error }}</div>
2019-03-18 08:53:00 -03:00
</div>
</template>
<script>
export default {
inheritAttrs: false,
props: {
id: {
type: String,
default() {
return `select-input-${this._uid}`
},
},
2019-04-03 17:43:10 -03:00
value: [String, Number, Boolean],
2019-03-18 08:53:00 -03:00
label: String,
2020-09-08 17:14:52 -03:00
error: String,
2019-03-18 08:53:00 -03:00
},
data() {
return {
selected: this.value,
}
},
watch: {
selected(selected) {
this.$emit('input', selected)
},
},
methods: {
focus() {
this.$refs.input.focus()
},
select() {
this.$refs.input.select()
},
},
}
</script>