feat: Add basic autocomplete using redisearch

This commit is contained in:
Hussain Nagaria
2021-04-21 13:52:23 +05:30
committed by marination
parent 71f4b98d0c
commit 0c47f3a876
5 changed files with 179 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
{% extends "templates/web.html" %}
{% block title %}{{ _('Search') }}{% endblock %}
{% block header %}
<div class="mb-6">{{ _('Search Products') }}</div>
{% endblock header %}
{% block page_content %}
<input type="text" name="query" id="search-box">
<ul id="results">
</ul>
{% endblock %}

View File

@@ -0,0 +1,25 @@
console.log("search.js loaded");
const search_box = document.getElementById("search-box");
const results = document.getElementById("results");
function populateResults(data) {
html = ""
for (let res of data.message) {
html += `<li>${res}</li>`
}
console.log(html);
results.innerHTML = html;
}
search_box.addEventListener("input", (e) => {
frappe.call({
method: "erpnext.templates.pages.product_search.search",
args: {
query: e.target.value
},
callback: (data) => {
populateResults(data);
}
})
});