2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/ui/components/controls/Autocomplete.vue
2018-06-27 20:08:27 +05:30

85 lines
1.8 KiB
Vue

<script>
import Awesomplete from 'awesomplete';
import Data from './Data';
export default {
extends: Data,
data() {
return {
awesomplete: null
}
},
mounted() {
this.setupAwesomplete();
this.awesomplete.container.classList.add('form-control');
this.awesomplete.ul.classList.add('dropdown-menu');
},
methods: {
getInputListeners() {
return {
input: async e => {
this.awesomplete.list = await this.getList(e.target.value);
},
'awesomplete-select': e => {
const value = e.text.value;
this.handleChange(value);
}
}
},
getList(text) {
return this.docfield.getList(text);
},
setupAwesomplete() {
const input = this.$refs.input;
this.awesomplete = new Awesomplete(input, {
minChars: 0,
maxItems: 99,
sort: this.sort(),
filter: this.filter(),
item: (text, input) => {
const li = document.createElement('li');
li.classList.add('dropdown-item');
li.classList.add('d-flex');
li.classList.add('align-items-center');
li.innerHTML = text.label;
return li;
}
});
this.bindEvents();
},
bindEvents() {
},
sort() {
// return a function that handles sorting of items
},
filter() {
// return a function that filters list suggestions based on input
}
}
};
</script>
<style lang="scss">
@import "../../styles/variables";
@import "~awesomplete/awesomplete.base";
.awesomplete {
padding: 0;
border: none;
& > ul {
padding: $dropdown-padding-y 0;
}
.dropdown-menu:not([hidden]) {
display: block;
}
.dropdown-item[aria-selected="true"] {
background-color: $dropdown-link-hover-bg;
}
}
</style>