pingcrm/resources/js/Shared/SelectInput.vue

48 lines
977 B
Vue
Raw Normal View History

2019-03-18 08:53:00 -03:00
<template>
2021-12-08 14:40:19 -03:00
<div :class="$attrs.class">
2019-03-18 08:53:00 -03:00
<label v-if="label" class="form-label" :for="id">{{ label }}:</label>
2021-12-08 14:40:19 -03:00
<select :id="id" ref="input" v-model="selected" v-bind="{ ...$attrs, class: null }" 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>
2021-12-08 12:15:39 -03:00
import { v4 as uuid } from 'uuid'
2019-03-18 08:53:00 -03:00
export default {
inheritAttrs: false,
props: {
id: {
type: String,
default() {
2021-12-08 12:15:39 -03:00
return `select-input-${uuid()}`
2019-03-18 08:53:00 -03:00
},
},
2020-09-08 17:14:52 -03:00
error: String,
2021-12-08 12:15:39 -03:00
label: String,
modelValue: [String, Number, Boolean],
2019-03-18 08:53:00 -03:00
},
2021-12-08 14:52:56 -03:00
emits: ['update:modelValue'],
2019-03-18 08:53:00 -03:00
data() {
return {
2021-12-08 12:15:39 -03:00
selected: this.modelValue,
2019-03-18 08:53:00 -03:00
}
},
watch: {
selected(selected) {
2021-12-08 12:15:39 -03:00
this.$emit('update:modelValue', selected)
2019-03-18 08:53:00 -03:00
},
},
methods: {
focus() {
this.$refs.input.focus()
},
select() {
this.$refs.input.select()
},
},
}
</script>