Added save functionality

This commit is contained in:
2026-04-04 18:10:01 +10:00
parent 4ed4110ba0
commit 6bb6ff7f71
12 changed files with 384 additions and 47 deletions
@@ -0,0 +1,51 @@
<script setup lang="ts">
import { ref, nextTick } from 'vue'
import axios from 'axios'
const props = defineProps<{
prefilledOptions: { value: number, title: string }[]
errorMessages?: string[] | string
}>()
const model = defineModel<{ value: number, title: string } | null>()
const aircraftOptions = ref(props.prefilledOptions ?? [])
const autocompleteRef = ref<any>(null)
const onFocus = () => {
nextTick(() => {
const input = autocompleteRef.value?.$el?.querySelector('input')
input?.select()
})
}
const searchAircraft = async (query: string) => {
if (!query || query.length < 2) {
aircraftOptions.value = props.prefilledOptions ?? []
return
}
if (query === model.value?.title) return
const { data } = await axios.get('/search/aircraft', { params: { q: query } })
aircraftOptions.value = data
}
</script>
<template>
<v-autocomplete
ref="autocompleteRef"
v-model="model"
label="Aircraft"
:items="aircraftOptions"
:error-messages="errorMessages"
item-title="title"
@update:search="searchAircraft"
@focus="onFocus"
hint="Showing closest matches to the imported value"
placeholder="B738"
clearable
hide-no-data
return-object
/>
</template>