working an AddEmployeeModal
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<template lang="pug">
|
||||
|
||||
div.modal.fade#addEmployeeModal(
|
||||
div.modal.fade(
|
||||
:id="modalId"
|
||||
tabindex="-1"
|
||||
aria-labelledby="addEmployeeModalLabel"
|
||||
aria-hidden="false"
|
||||
@@ -13,41 +14,104 @@ div.modal.fade#addEmployeeModal(
|
||||
button.btn-close(
|
||||
type="button"
|
||||
aria-label="Close"
|
||||
@click=""
|
||||
@click="closeModal()"
|
||||
)
|
||||
.modal-body
|
||||
input.form-control(
|
||||
|
||||
v-model="query"
|
||||
@input="onChange($event)"
|
||||
)
|
||||
ul.dropdown-menu(
|
||||
|
||||
)
|
||||
li.dropdown-item(
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
.card.p-0(v-show="isOpenSuggestions")
|
||||
ul.list-group.text-start
|
||||
li.dropdown-item(
|
||||
v-for="(sugg, i) in suggestions"
|
||||
:key="i"
|
||||
@click="setResult(sugg)"
|
||||
) {{sugg.name}}
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { Modal } from 'bootstrap'
|
||||
import { computed, ref } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
|
||||
|
||||
/**
|
||||
* Begin definitions
|
||||
*/
|
||||
const props = defineProps<{
|
||||
modalId: string,
|
||||
searchData : [],
|
||||
searchFields? : string[],
|
||||
sourceRow? : number,
|
||||
minQueryLength? : number
|
||||
}>()
|
||||
|
||||
console.log("hi")
|
||||
const emit = defineEmits<{
|
||||
(e: 'emitResult', result : Employee) : Employee
|
||||
}>()
|
||||
|
||||
/* const addEmployeeSuggestions = computed(() => {
|
||||
return employees.value.filter((el: { name: string }) => {
|
||||
return el.name.toLowerCase().search(addEmployeeInput.value.toLowerCase()) > 0
|
||||
const query : Ref<string> = ref('')
|
||||
const isOpenSuggestions : Ref<boolean> = ref(false)
|
||||
const suggestions : Ref<Employee[]> = ref([])
|
||||
const result : Ref<Employee | undefined> = ref()
|
||||
/**
|
||||
* End definitions
|
||||
*
|
||||
*
|
||||
*
|
||||
* Begin functions
|
||||
*/
|
||||
function filterResults(query : string) {
|
||||
suggestions.value = props.searchData.filter((el: { name: string }) => {
|
||||
return el.name.toLowerCase().search(query.toLowerCase()) > -1
|
||||
})
|
||||
}) */
|
||||
}
|
||||
|
||||
function setResult(pResult : Employee) {
|
||||
result.value = pResult
|
||||
query.value = pResult.name
|
||||
isOpenSuggestions.value = false
|
||||
emit('emitResult', result.value)
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
let modal = Modal.getInstance(document.getElementById(props.modalId))
|
||||
query.value = ''
|
||||
result.value = undefined
|
||||
suggestions.value = []
|
||||
isOpenSuggestions.value = false
|
||||
modal.hide()
|
||||
}
|
||||
/**
|
||||
* End Functions
|
||||
*
|
||||
*
|
||||
* Begin Event listeners
|
||||
*/
|
||||
function onChange(event : Event){
|
||||
let query : string = (<HTMLInputElement>event?.target).value
|
||||
|
||||
if(query.length >= (props.minQueryLength ?? 1)) {
|
||||
filterResults(query)
|
||||
isOpenSuggestions.value = true
|
||||
}
|
||||
else {
|
||||
isOpenSuggestions.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
li.dropdown-item:active,
|
||||
li.dropdown-item.active {
|
||||
color: black;
|
||||
background-color: #e9ecef;
|
||||
}
|
||||
|
||||
li.dropdown-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user