[24456] Debounce remote-field-updater rather than throttle

pull/5348/head
Oliver Günther 8 years ago
parent 059c7ba50d
commit 6515c8ff19
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 5
      frontend/app/components/common/remote/remote-field-updater.directive.test.ts
  2. 4
      frontend/app/components/common/remote/remote-field-updater.directive.ts

@ -56,18 +56,21 @@ describe('remote-field-updater directive', function() {
element.remove();
});
it('should request the given url on input', function() {
it('should request the given url on input', function(done) {
$httpBackend.expectGET('/foo/bar?q=foobar').respond(200, '<span>response!</span>');
var input = element.find('.remote-field--input');
var e = jQuery.Event('keyup');
e.keyCode = 65;
input.val('foobar').trigger(e);
setTimeout(() => {
$httpBackend.flush();
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
expect(element.find('.remote-field--target span').length).to.eql(1);
done();
}, 1500);
});
});

@ -86,7 +86,7 @@ function remoteFieldUpdater($http:ng.IHttpService) {
});
}
input.on('keyup change', _.throttle(function(event:any) {
input.on('keyup change', _.debounce(function(event:any) {
// This prevents an update of the result list when
// tabbing to the result list (9),
// pressing enter (13)
@ -97,7 +97,7 @@ function remoteFieldUpdater($http:ng.IHttpService) {
if (keyCodesArray.indexOf(event.keyCode) == -1 && event.keyCode != undefined) {
updater();
}
}, 1000, { leading: true })
}, 1000)
);
}
};

Loading…
Cancel
Save