]>
Commit | Line | Data |
---|---|---|
69a1a90c | 1 | var awp = Awesomplete.$; |
430ff071 A |
2 | var autocompleteFields = document.querySelectorAll('input[data-multiple]'); |
3 | [].forEach.call(autocompleteFields, function(autocompleteField) { | |
4 | awesomplete = new Awesomplete(awp(autocompleteField), { | |
5 | filter: function (text, input) { | |
6 | return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]); | |
7 | }, | |
8 | replace: function (text) { | |
9 | var before = this.input.value.match(/^.+ \s*|/)[0]; | |
10 | this.input.value = before + text + " "; | |
11 | }, | |
12 | minChars: 1 | |
13 | }) | |
b39b1bc2 A |
14 | }); |
15 | ||
16 | /** | |
17 | * Remove already selected items from autocompletion list. | |
18 | * HTML list is never updated, so removing a tag will add it back to awesomplete. | |
19 | * | |
20 | * FIXME: This a workaround waiting for awesomplete to handle this. | |
21 | * https://github.com/LeaVerou/awesomplete/issues/16749 | |
22 | */ | |
23 | function awesompleteUniqueTag(selector) { | |
24 | var input = document.querySelector(selector); | |
25 | input.addEventListener('input', function() | |
26 | { | |
27 | proposedTags = input.getAttribute('data-list').replace(/,/g, '').split(' '); | |
28 | reg = /(\w+) /g; | |
29 | while((match = reg.exec(input.value)) !== null) { | |
30 | id = proposedTags.indexOf(match[1]); | |
31 | if(id != -1 ) { | |
32 | proposedTags.splice(id, 1); | |
33 | } | |
34 | } | |
35 | ||
36 | awesomplete.list = proposedTags; | |
37 | }); | |
38 | } |