fix: keyword autocompleteItems
This commit is contained in:
parent
393f2fa2c5
commit
7edd30ab0a
3 changed files with 50 additions and 51 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, onUnmounted, ref } from 'vue'
|
import { onMounted, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
const storesKeyword = ['test1', 'test2', 'test3', 'test4', 'test5']
|
||||||
|
const filterOptions = ref(storesKeyword)
|
||||||
|
const inputKeyword = ref<string[]>([])
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
open: boolean
|
open: boolean
|
||||||
|
|
@ -13,7 +17,7 @@ const props = withDefaults(
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
open: false,
|
open: false,
|
||||||
},
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
|
|
@ -53,6 +57,29 @@ function submit() {
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createkeyword(val, done) {
|
||||||
|
if (val.length > 2) {
|
||||||
|
if (!inputKeyword.value.includes(val)) {
|
||||||
|
inputKeyword.value.push(val)
|
||||||
|
done(val, 'add-unique')
|
||||||
|
console.log(inputKeyword.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterkeyword(val, update) {
|
||||||
|
update(() => {
|
||||||
|
if (val === '') {
|
||||||
|
filterOptions.value = storesKeyword
|
||||||
|
} else {
|
||||||
|
const needle = val.toLowerCase()
|
||||||
|
filterOptions.value = storesKeyword.filter(
|
||||||
|
(v) => v.toLowerCase().indexOf(needle) > -1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => window.addEventListener('keydown', keydown))
|
onMounted(() => window.addEventListener('keydown', keydown))
|
||||||
onUnmounted(() => window.addEventListener('keydown', keydown))
|
onUnmounted(() => window.addEventListener('keydown', keydown))
|
||||||
|
|
||||||
|
|
@ -150,14 +177,26 @@ const file = ref<File | undefined>()
|
||||||
|
|
||||||
<section class="q-mb-md">
|
<section class="q-mb-md">
|
||||||
<span class="text-weight-bold">คำสำคัญ</span>
|
<span class="text-weight-bold">คำสำคัญ</span>
|
||||||
<q-input
|
<div class="q-mt-md">
|
||||||
outlined
|
<q-select
|
||||||
dense
|
outlined
|
||||||
class="q-mt-sm"
|
v-model="inputKeyword"
|
||||||
placeholder="คำสำคัญ"
|
use-input
|
||||||
:model-value="keyword"
|
use-chips
|
||||||
@update:model-value="(v) => $emit('update:keyword', v)"
|
multiple
|
||||||
/>
|
input-debounce="0"
|
||||||
|
@new-value="createkeyword"
|
||||||
|
:options="filterOptions"
|
||||||
|
@filter="filterkeyword"
|
||||||
|
style="width: 250px"
|
||||||
|
>
|
||||||
|
<template v-slot:no-option>
|
||||||
|
<q-item>
|
||||||
|
<q-item-section class="text-grey"> No results </q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section :style="{ display: 'flex', gap: '.5rem' }">
|
<section :style="{ display: 'flex', gap: '.5rem' }">
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ const onRowClick = (evt: Event, row: TreeDataFolder, index: number) => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="q-pa-md">
|
<div class="q-mt-md">
|
||||||
<div class="q-gutter-sm">
|
<div class="q-gutter-sm">
|
||||||
<div
|
<div
|
||||||
class="flex flex-break d justify-between space-between"
|
class="flex flex-break d justify-between space-between"
|
||||||
|
|
@ -331,7 +331,7 @@ const onRowClick = (evt: Event, row: TreeDataFolder, index: number) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="q-pa-md" v-if="currentDept >= 3">
|
<div class="q-mt-md" v-if="currentDept >= 3">
|
||||||
<div class="q-gutter-sm">
|
<div class="q-gutter-sm">
|
||||||
<div class="flex flex-break d justify-between space-between">
|
<div class="flex flex-break d justify-between space-between">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import { onMounted, ref } from "vue";
|
|
||||||
import TagInput from "@mayank1513/vue-tag-input";
|
|
||||||
import "@mayank1513/vue-tag-input/style.css";
|
|
||||||
|
|
||||||
const autocompleteItems = [
|
|
||||||
"No dependencies",
|
|
||||||
"Autocompletion",
|
|
||||||
"Keep Focused",
|
|
||||||
"Fast Settup",
|
|
||||||
"Mini Sized",
|
|
||||||
"Customizable",
|
|
||||||
"Backspace/Delete to remove tag",
|
|
||||||
"Turns red when backspace/delete is pressed",
|
|
||||||
"Examples",
|
|
||||||
"Docs",
|
|
||||||
"Copy/Paste",
|
|
||||||
]
|
|
||||||
const tags = ref<string[]>([]);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<q-btn @click="()=> {console.log(tags);
|
|
||||||
}">test</q-btn>
|
|
||||||
<tag-input tagBgColor="rgb(189, 184, 179)" :autocomplete-items="autocompleteItems" v-model="tags" />
|
|
||||||
<!-- <q-btn
|
|
||||||
class="q-px-md"
|
|
||||||
label="บันทึก"
|
|
||||||
type="submit"
|
|
||||||
color="primary"
|
|
||||||
dense
|
|
||||||
@click="
|
|
||||||
() => {
|
|
||||||
$emit('update:drawerFile')
|
|
||||||
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/> -->
|
|
||||||
</template>
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue