Select trie based on data attr

This commit is contained in:
Mouse Reeve 2022-01-12 17:02:30 -08:00
parent 99ec87c67c
commit 34635b0c3f
2 changed files with 89 additions and 25 deletions

View file

@ -19,7 +19,9 @@
const input = event.target;
// Get suggestions
let suggestions = getSuggestions(input.value, mimetypeTrie);
let trie = tries[input.getAttribute("data-autocomplete")];
let suggestions = getSuggestions(input.value, trie);
const boxId = input.getAttribute("list");
@ -80,32 +82,83 @@
});
})();
const mimetypeTrie = {
a: {
const tries = {"mimetype": {
a: {
c: "AAC",
a: {
c: "AAC",
},
z: {
w: "AZW",
},
},
z: {
w: "AZW",
},
},
d: "Daisy",
e: "ePub",
f: "FLAC",
h: "HTML",
m: {
4: {
a: "M4A",
b: "M4B",
},
o: "MOBI",
p: "MP3",
},
o: "OGG",
p: {
d: {
f: "PDF",
a: {
i: {
s: {
y: "Daisy",
},
},
},
},
e: {
p: {
u: {
b: "ePub",
},
},
},
f: {
l: {
a: {
c: "FLAC",
},
},
},
h: {
t: {
m: {
l: "HTML",
},
},
},
m: {
4: {
a: "M4A",
b: "M4B",
},
o: {
b: {
i: "MOBI",
},
},
p: {
3: "MP3",
},
},
o: {
g: {
g: "OGG",
},
},
p: {
d: {
f: "PDF",
},
l: {
a: {
i: {
n: {
t: {
e: {
x: {
t: "Plaintext",
},
},
},
},
},
},
},
},
l: "Plaintext",
},
};

View file

@ -27,7 +27,18 @@
</div>
<div class="column is-one-fifth">
<label class="label" for="id_filetype">{% trans "File type:" %}</label>
<input type="text" name="filetype" maxlength="5" class="input" required="" id="id_filetype" value="{% firstof file_link_form.filetype.value "" %}" placeholder="PDF" list="mimetypes-list" data-autocomplete="mimetype">
<input
type="text"
name="filetype"
maxlength="5"
class="input"
required=""
id="id_filetype"
value="{% firstof file_link_form.filetype.value '' %}"
placeholder="ePub"
list="mimetypes-list"
data-autocomplete="mimetype"
>
<datalist id="mimetypes-list"></datalist>
{% include 'snippets/form_errors.html' with errors_list=file_link_form.filetype.errors id="desc_filetype" %}
</div>