Skip to content

Commit

Permalink
update filter widget to wait 2s after last key up
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed May 7, 2017
1 parent 74df228 commit 5409e2c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions app/core/widgets/FilterWidget.js
Expand Up @@ -26,7 +26,7 @@ define([
},

events: {
'keyup .js-search': 'search',
'keyup .js-search': 'onKeyUp',

'click .js-search-clear': 'clearFilters',

Expand Down Expand Up @@ -74,13 +74,26 @@ define([
}
},

search: function (event) {
if (event.which != 13) {
return;
}

onKeyUp: function (event) {
var self = this;
var $element = $(event.currentTarget);
var searchString = this.searchString = $element.val();

if (event.which == 13) {
return self.search(searchString);
}

if (this.searchTimeOut) {
clearTimeout(this.searchTimeOut);
this.searchTimeOut = null;
}

this.searchTimeOut = setTimeout(function () {
self.search(searchString);
}, 2000);
},

search: function (searchString) {
var filterIndex = -1;
_.each(this.options.filters, function (item, index) {
if (item.filterData.id === 'q') {
Expand All @@ -89,7 +102,7 @@ define([
});

if (filterIndex >= 0) {
this.options.filters[filterIndex].filterData.value = $element.val();
this.options.filters[filterIndex].filterData.value = searchString;
} else {
this.options.filters.push({
filterData: {
Expand Down

0 comments on commit 5409e2c

Please sign in to comment.