Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 253c49f

Browse files
fix(typeahead): prevent accidental form submission on ENTER
1 parent 85647c9 commit 253c49f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/typeahead/test/typeahead.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('typeahead tests', function () {
6060
var e = $.Event("keydown");
6161
e.which = keyCode;
6262
inputEl.trigger(e);
63+
return e;
6364
};
6465

6566
//custom matchers
@@ -438,6 +439,13 @@ describe('typeahead tests', function () {
438439
expect($scope.isLoading).toBeFalsy();
439440
});
440441

442+
it('pr 1165 - prevent default on ENTER to avoid accidental form submission', function () {
443+
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>");
444+
var e = triggerKeyDown(element, 13);
445+
446+
expect(e.isDefaultPrevented()).toBeTruthy();
447+
});
448+
441449
it('does not close matches popup on click in input', function () {
442450
var element = prepareInputEl("<div><input ng-model='result' typeahead='item for item in source | filter:$viewValue'></div>");
443451
var inputEl = findInput(element);

src/typeahead/typeahead.js

+3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
228228

229229
//typeahead is open and an "interesting" key was pressed
230230
if (scope.matches.length === 0 || HOT_KEYS.indexOf(evt.which) === -1) {
231+
if (evt.which === 13) {
232+
evt.preventDefault();
233+
}
231234
return;
232235
}
233236

0 commit comments

Comments
 (0)