Added delete key support for auto complete
This commit is contained in:
parent
72e9400e1d
commit
04a16a2a36
2 changed files with 23 additions and 14 deletions
|
@ -7,6 +7,7 @@ App.Controls.AutoCompleteInput = function($input) {
|
|||
var tagList = App.DI.get('tagList');
|
||||
|
||||
var KEY_RETURN = 13;
|
||||
var KEY_DELETE = 46;
|
||||
var KEY_ESCAPE = 27;
|
||||
var KEY_UP = 38;
|
||||
var KEY_DOWN = 40;
|
||||
|
@ -17,6 +18,7 @@ App.Controls.AutoCompleteInput = function($input) {
|
|||
maxResults: 15,
|
||||
minLengthToArbitrarySearch: 3,
|
||||
onApply: null,
|
||||
onDelete: null,
|
||||
onRender: null,
|
||||
additionalFilter: null,
|
||||
};
|
||||
|
@ -63,27 +65,24 @@ App.Controls.AutoCompleteInput = function($input) {
|
|||
}
|
||||
|
||||
$input.bind('keydown', function(e) {
|
||||
var func = null;
|
||||
if (isShown() && e.which === KEY_ESCAPE) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
hide();
|
||||
func = hide;
|
||||
} else if (isShown() && e.which === KEY_DOWN) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
selectNext();
|
||||
func = selectNext;
|
||||
} else if (isShown() && e.which === KEY_UP) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
selectPrevious();
|
||||
func = selectPrevious;
|
||||
} else if (isShown() && e.which === KEY_RETURN && activeResult >= 0) {
|
||||
func = function() { applyAutocomplete(); hide(); };
|
||||
} else if (isShown() && e.which === KEY_DELETE && activeResult >= 0) {
|
||||
func = function() { applyDelete(); hide(); };
|
||||
}
|
||||
|
||||
if (func !== null) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
applyAutocomplete();
|
||||
hide();
|
||||
func();
|
||||
} else {
|
||||
window.clearTimeout(showTimeout);
|
||||
showTimeout = window.setTimeout(showOrHide, 250);
|
||||
|
@ -182,6 +181,12 @@ App.Controls.AutoCompleteInput = function($input) {
|
|||
}
|
||||
}
|
||||
|
||||
function applyDelete() {
|
||||
if (options.onDelete) {
|
||||
options.onDelete(results[activeResult].tag);
|
||||
}
|
||||
}
|
||||
|
||||
function applyAutocomplete() {
|
||||
if (options.onApply) {
|
||||
options.onApply(results[activeResult].tag);
|
||||
|
|
|
@ -74,6 +74,10 @@ App.Controls.TagInput = function($underlyingInput) {
|
|||
|
||||
function initAutoComplete() {
|
||||
var autoComplete = new App.Controls.AutoCompleteInput($input);
|
||||
autoComplete.onDelete = function(text) {
|
||||
removeTag(text);
|
||||
$input.val('');
|
||||
};
|
||||
autoComplete.onApply = function(text) {
|
||||
processText(text, SOURCE_AUTOCOMPLETION);
|
||||
$input.val('');
|
||||
|
|
Loading…
Reference in a new issue