2019-03-18 08:53:00 -03:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<label v-if="label" class="form-label" :for="id">{{ label }}:</label>
|
2019-04-15 22:18:29 -03:00
|
|
|
<select :id="id" ref="input" v-model="selected" v-bind="$attrs" class="form-select" :class="{ error: errors.length }">
|
2019-03-18 08:53:00 -03:00
|
|
|
<slot />
|
|
|
|
</select>
|
2019-04-15 22:18:29 -03:00
|
|
|
<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 `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,
|
2019-04-15 22:18:29 -03:00
|
|
|
errors: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
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>
|