mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add callback for search text entery
This commit is contained in:
parent
7d68b3209b
commit
c4ac7e1877
@ -6,6 +6,7 @@
|
||||
/* exported
|
||||
closeSearchPanel,
|
||||
openSearchPanel,
|
||||
searchTextChanged,
|
||||
*/
|
||||
|
||||
|
||||
@ -30,5 +31,64 @@ function openSearchPanel() {
|
||||
// Finally, grab keyboard focus in the search bar
|
||||
panel.find('#search-input').focus();
|
||||
|
||||
panel.find('#search-input').on('keyup change', searchTextChanged);
|
||||
|
||||
}
|
||||
|
||||
var searchRequests = [];
|
||||
var searchInputTimer = null;
|
||||
var searchText = null;
|
||||
var searchTextPrevious = null;
|
||||
|
||||
function searchTextChanged(event) {
|
||||
|
||||
searchText = $('#offcanvas-search').find('#search-input').val();
|
||||
|
||||
clearTimeout(searchInputTimer);
|
||||
searchInputTimer = setTimeout(updateSearch, 250);
|
||||
};
|
||||
|
||||
|
||||
function updateSearch() {
|
||||
|
||||
if (searchText == searchTextPrevious) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchText.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
searchTextPrevious = searchText;
|
||||
|
||||
// Search for matching parts
|
||||
inventreeGet(
|
||||
`{% url "api-part-list" %}`,
|
||||
{
|
||||
search: searchText,
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
},
|
||||
{
|
||||
success: function(results) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Search for matching stock items
|
||||
inventreeGet(
|
||||
'{% url "api-stock-list" %}',
|
||||
{
|
||||
search: searchText,
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
},
|
||||
{
|
||||
success: function(results) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user