Very often in some parts of my application there is a search box that takes a row and then filters the table based on the row.
What I am aiming at is the ability to allow the user to enter something and automatically after a few ms of delay, when the results are updated themselves. no need to press the enter button.
Data will be sorted using AngularJs filters. However, before we update the filter, I believe that we first need to understand that the user has completed input and is now waiting for the results.
So, I have outlined a directive that will be attached to the search input field.
<input type="text" update-filter placeholder="Enter search term"> //and the directive goes like this app.directive('updateFilter', [ '$timeout', function($timeout){ var delay; return { link: function(scope, element){ element.on('keypress', function(){ if(!delay) { delay = $timeout(function() { //perform the activity of updating the filter here delay = undefined; },50); } } } } });
My question is, is this approach right for solving this problem or are there better solutions there?
source share