search pills: Backspace should remove a search pill with typeahead open.

Fixes part of #10026.

Typeaheads stopped propogation of keydown and keyup events for any
key except tab and enter. If stopAdvance was true even tab and enter
were not allowed.

advanceKeyCodes option was added to typeahead which allowed to specify
key codes for which propogation of keydown and keyup events should not
stop. advanceKeyCodes does not respect the stopAdvance option.
As the backspace key code is added to advanceKeyCodes in search.js,
the backspace key deletes pill on pressing backspace if input is empty
or only consists of spaces.
This commit is contained in:
Shubham Padia 2018-07-28 11:03:24 +05:30 committed by Tim Abbott
parent 4186ebe56a
commit 28589c5563
2 changed files with 6 additions and 2 deletions

View File

@ -117,6 +117,7 @@ exports.initialize = function () {
return items;
},
stopAdvance: page_params.search_pills_enabled,
advanceKeyCodes: [8],
});
searchbox_form.on('compositionend', function () {

View File

@ -2046,7 +2046,8 @@
break
}
if (this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13)) {
if ((this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13))
&& $.inArray(e.keyCode, this.options.advanceKeyCodes)) {
e.stopPropagation()
}
}
@ -2082,7 +2083,8 @@
this.lookup()
}
if (this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13)) {
if ((this.options.stopAdvance || (e.keyCode != 9 && e.keyCode != 13))
&& $.inArray(e.keyCode, this.options.advanceKeyCodes)) {
e.stopPropagation()
}
@ -2133,6 +2135,7 @@
, minLength: 1
, stopAdvance: false
, dropup: false
, advanceKeyCodes: []
}
$.fn.typeahead.Constructor = Typeahead