worked on autocomplete modal, solved #1
This commit is contained in:
@@ -4,7 +4,7 @@ div.modal.fade(
|
|||||||
:id="modalId"
|
:id="modalId"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
aria-labelledby="addEmployeeModalLabel"
|
aria-labelledby="addEmployeeModalLabel"
|
||||||
aria-hidden="false"
|
aria-hidden="true"
|
||||||
data-bs-focus="true"
|
data-bs-focus="true"
|
||||||
)
|
)
|
||||||
.modal-dialog
|
.modal-dialog
|
||||||
@@ -14,12 +14,15 @@ div.modal.fade(
|
|||||||
button.btn-close(
|
button.btn-close(
|
||||||
type="button"
|
type="button"
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
@click="closeModal()"
|
data-bs-dismiss="modal"
|
||||||
)
|
)
|
||||||
.modal-body
|
.modal-body
|
||||||
input.form-control(
|
input.form-control#inputAutocomplete(
|
||||||
v-model="query"
|
v-model="query"
|
||||||
@input="onChange($event)"
|
@input="onChange($event)"
|
||||||
|
@keypress.enter="onEnter"
|
||||||
|
@keypress.down="onDown"
|
||||||
|
@keypress.up="onUp"
|
||||||
)
|
)
|
||||||
.card.p-0(v-show="isOpenSuggestions")
|
.card.p-0(v-show="isOpenSuggestions")
|
||||||
ul.list-group.text-start
|
ul.list-group.text-start
|
||||||
@@ -27,15 +30,15 @@ div.modal.fade(
|
|||||||
v-for="(sugg, i) in suggestions"
|
v-for="(sugg, i) in suggestions"
|
||||||
:key="i"
|
:key="i"
|
||||||
@click="setResult(sugg)"
|
@click="setResult(sugg)"
|
||||||
|
:class="{'active' : selected === i}"
|
||||||
) {{sugg.name}}
|
) {{sugg.name}}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Modal } from 'bootstrap'
|
import { Modal } from 'bootstrap'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref, onMounted } from 'vue'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin definitions
|
* Begin definitions
|
||||||
*/
|
*/
|
||||||
@@ -55,6 +58,8 @@ div.modal.fade(
|
|||||||
const isOpenSuggestions : Ref<boolean> = ref(false)
|
const isOpenSuggestions : Ref<boolean> = ref(false)
|
||||||
const suggestions : Ref<Employee[]> = ref([])
|
const suggestions : Ref<Employee[]> = ref([])
|
||||||
const result : Ref<Employee | undefined> = ref()
|
const result : Ref<Employee | undefined> = ref()
|
||||||
|
const selected : Ref<number> = ref(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End definitions
|
* End definitions
|
||||||
*
|
*
|
||||||
@@ -75,14 +80,6 @@ div.modal.fade(
|
|||||||
emit('emitResult', result.value)
|
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
|
* End Functions
|
||||||
*
|
*
|
||||||
@@ -100,14 +97,49 @@ div.modal.fade(
|
|||||||
isOpenSuggestions.value = false
|
isOpenSuggestions.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onModalHide() {
|
||||||
|
query.value = ''
|
||||||
|
result.value = undefined
|
||||||
|
suggestions.value = []
|
||||||
|
isOpenSuggestions.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function onEnter() {
|
||||||
|
if(selected.value > -1 && selected.value < suggestions.value.length ) {
|
||||||
|
setResult(suggestions.value[selected.value])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDown() {
|
||||||
|
if (selected.value < suggestions.value.length - 1) {
|
||||||
|
selected.value++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onUp() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lifecycle Hooks
|
||||||
|
*/
|
||||||
|
onMounted(() => {
|
||||||
|
let modal = document.getElementById(props.modalId);
|
||||||
|
|
||||||
|
modal?.addEventListener('hide.bs.modal', onModalHide)
|
||||||
|
|
||||||
|
modal?.addEventListener('shown.bs.modal', () => {
|
||||||
|
document.getElementById('inputAutocomplete')?.focus()
|
||||||
|
})
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
li.dropdown-item:active,
|
li.dropdown-item:active,
|
||||||
li.dropdown-item.active {
|
li.dropdown-item.active {
|
||||||
color: black;
|
|
||||||
background-color: #e9ecef;
|
background-color: #e9ecef;
|
||||||
|
color: #1e2125;
|
||||||
}
|
}
|
||||||
|
|
||||||
li.dropdown-item {
|
li.dropdown-item {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ AddEmployeeModal(
|
|||||||
:searchFields="['name']"
|
:searchFields="['name']"
|
||||||
:searchRow="addEmployeeRow"
|
:searchRow="addEmployeeRow"
|
||||||
:modalId="modalId"
|
:modalId="modalId"
|
||||||
|
@emitResult="addEmployee($event)"
|
||||||
)
|
)
|
||||||
|
|
||||||
//- TODO: #2 Can't highlight list-group-item when hovering
|
//- TODO: #2 Can't highlight list-group-item when hovering
|
||||||
@@ -121,15 +122,11 @@ table(class='table table-bordered table-sm' v-for="(row, rIndex) in scheduleData
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function addEmployee(param : Employee){
|
function addEmployee(param : Employee){
|
||||||
console.log(addEmployeeRow.value)
|
|
||||||
console.log(param)
|
|
||||||
|
|
||||||
if (addEmployeeRow.value !== undefined && param !== null) {
|
if (addEmployeeRow.value !== undefined && param !== null) {
|
||||||
scheduleData.value[addEmployeeRow.value].employees.push(param)
|
scheduleData.value[addEmployeeRow.value].employees.push(param)
|
||||||
addEmployeeRow.value = undefined
|
addEmployeeRow.value = undefined
|
||||||
addEmployeeInput.value = ''
|
addEmployeeInput.value = ''
|
||||||
}
|
}
|
||||||
console.log(scheduleData.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user