Skip to content

Instantly share code, notes, and snippets.

@mtribone
Last active July 2, 2019 17:05
Show Gist options
  • Save mtribone/e32381babd0720fa72d5f6c5d393d47f to your computer and use it in GitHub Desktop.
Save mtribone/e32381babd0720fa72d5f6c5d393d47f to your computer and use it in GitHub Desktop.
JS bits for the Autocomplete HTML
Autocomplete.prototype.onTextBoxType = function(e) {
// only show options if user typed something
if(this.textBox.val().trim().length > 0) {
// get options based on value
var options = this.getOptions(this.textBox.val().
trim().toLowerCase());
// build the menu based on the options
this.buildMenu(options);
// show the menu
this.showMenu();
// update the live region
this.updateStatus(options.length);
}
// update the select box value which
// the server uses to process the data
this.updateSelectBox();
};
Autocomplete.prototype.onTextBoxKeyUp = function(e) {
switch (e.keyCode) {
case this.keys.esc:
case this.keys.up:
case this.keys.left:
case this.keys.right:
case this.keys.space:
case this.keys.enter:
case this.keys.tab:
case this.keys.shift:
// ignore these keys otherwise the menu will show briefly
break;
case this.keys.down:
this.onTextBoxDownPressed(e);
break;
default:
this.onTextBoxType(e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment