diff --git a/ckan/public/base/javascript/modules/autocomplete.js b/ckan/public/base/javascript/modules/autocomplete.js index a7b292d3c07..52bd24f1f89 100644 --- a/ckan/public/base/javascript/modules/autocomplete.js +++ b/ckan/public/base/javascript/modules/autocomplete.js @@ -267,7 +267,7 @@ this.ckan.module('autocomplete', function (jQuery, _) { * Returns nothing. */ _onKeydown: function (event) { - if (event.which === 188) { + if (typeof event.key !== 'undefined' ? event.key === ',' : event.which === 188) { event.preventDefault(); setTimeout(function () { var e = jQuery.Event("keydown", { which: 13 }); diff --git a/ckan/public/base/test/spec/modules/autocomplete.spec.js b/ckan/public/base/test/spec/modules/autocomplete.spec.js index 93a8fb57a54..a0cadd874ab 100644 --- a/ckan/public/base/test/spec/modules/autocomplete.spec.js +++ b/ckan/public/base/test/spec/modules/autocomplete.spec.js @@ -276,7 +276,7 @@ describe('ckan.modules.AutocompleteModule()', function () { describe('._onKeydown(event)', function () { beforeEach(function () { - this.keyDownEvent = jQuery.Event("keydown", { which: 188 }); + this.keyDownEvent = jQuery.Event("keydown", { key: ',', which: 188 }); this.fakeEvent = {}; this.clock = sinon.useFakeTimers(); this.jQuery = sinon.stub(jQuery.fn, 'init', jQuery.fn.init); @@ -290,7 +290,7 @@ describe('ckan.modules.AutocompleteModule()', function () { this.Event.restore(); this.trigger.restore(); }); - + it('should trigger fake "return" keypress if a comma is pressed', function () { this.module._onKeydown(this.keyDownEvent); @@ -303,6 +303,7 @@ describe('ckan.modules.AutocompleteModule()', function () { }); it('should do nothing if another key is pressed', function () { + this.keyDownEvent.key = '╚'; this.keyDownEvent.which = 200; this.module._onKeydown(this.keyDownEvent); @@ -311,5 +312,16 @@ describe('ckan.modules.AutocompleteModule()', function () { assert.notCalled(this.Event); }); + + it('should do nothing if key is pressed which has the comma key-code but is not a comma', function () { + this.keyDownEvent.key = 'ת'; + this.keyDownEvent.which = 188; + + this.module._onKeydown(this.keyDownEvent); + + this.clock.tick(100); + + assert.notCalled(this.Event); + }); }); });