diff options
author | Marvin Borner | 2019-02-18 22:23:54 +0100 |
---|---|---|
committer | Marvin Borner | 2019-02-18 22:23:54 +0100 |
commit | 6794aa91dc95d71f60d33c4e59f0c204d70d23cc (patch) | |
tree | c4c4bf118d0f9392681f6200778d9347ac32630c /public | |
parent | 8e282ad2fc493aad7eed6c2d1cadbbe9495b1d52 (diff) |
Fixed autocomplete
Diffstat (limited to 'public')
-rw-r--r-- | public/scripts/chat.js | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 89bdff3..b89900c 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -295,32 +295,41 @@ function chat() { /** * Shows modal for adding a contact + * TODO: Fix selecting from dropdown on enter */ function addContact() { + let idComplete = false; const observer = new MutationObserver(() => { $('#contact_id_input') .on('keydown', (event) => { - if (event.keyCode === $.ui.keyCode.TAB - && $(this) - .autocomplete('instance').menu.active) { + if (event.keyCode === $.ui.keyCode.TAB) { + event.preventDefault(); + } else if (!idComplete && event.keyCode === $.ui.keyCode.ENTER) { event.preventDefault(); } }) .autocomplete({ - minLength: 0, - source: (request, response) => { + minLength: 1, + source(request, response) { response($.ui.autocomplete.filter( - wordList, request.term.split(/,\s*/) + wordList, request.term.split(/-\s*/) .pop(), )); }, - focus: () => false, - select: (event, ui) => { - const terms = this.value.split(/,\s*/); - terms.pop(); - terms.push(ui.item.value); - terms.push(''); - this.value = terms.join('-'); + focus() { + return false; + }, + select(event, ui) { + const words = this.value.split(/-\s*/); + words.pop(); + if (words.length !== 3) { + words.push(ui.item.value); + words.push(''); + this.value = words.join('-'); + } else { + this.value = `${words.join('-')}-${ui.item.value}`; + idComplete = true; + } return false; }, }); |