1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-06 01:50:26 +00:00

Implement category autocomplete

Loosely based on the one used in Betula
This commit is contained in:
Timur Ismagilov 2023-02-18 23:04:52 +03:00
parent e03d17f9a1
commit a9eeccb9b9
2 changed files with 28 additions and 3 deletions

View File

@ -21,9 +21,10 @@
{{end}}
{{if .GivenPermissionToModify}}
<li class="categories-card__entry categories-card__add-to-cat">
<form method="POST" action="/add-to-category" class="categories-card__add-form">
<input type="text" name="cat" id="_cat-name"
<form method="POST" action="/add-to-category" class="categories-card__add-form js-add-cat-form">
<input type="text" name="cat" id="_cat-name" class="js-add-cat-name"
placeholder="{{block `placeholder` .}}Category name...{{end}}">
<datalist class="js-add-cat-list" id="cat-name-options"></datalist>
<input type="hidden" name="hypha" value="{{$hyphaName}}">
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
<input type="submit" class="btn categories-card__btn" value="+"

View File

@ -22,4 +22,28 @@ hamburgerSection.classList.add("top-bar__section", "top-bar__section_hamburger")
hamburgerWrapper.appendChild(hamburger)
hamburgerSection.appendChild(hamburgerWrapper)
wrapper.appendChild(hamburgerSection)
wrapper.appendChild(hamburgerSection);
(async () => {
const input = document.querySelector('.js-add-cat-name'),
datalist = document.querySelector('.js-add-cat-list')
if (!input || !datalist) return;
const categories = await fetch('/category')
.then(resp => resp.text())
.then(html => {
return Array
.from(new DOMParser()
.parseFromString(html, 'text/html')
.querySelectorAll('.mv-category .p-name'))
.map(a => a.innerText);
});
for (let cat of categories) {
let optionElement = document.createElement('option')
optionElement.value = cat
datalist.appendChild(optionElement)
}
input.setAttribute('list', 'cat-name-options')
})();