Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created February 19, 2010 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmarkbage/308261 to your computer and use it in GitHub Desktop.
Save sebmarkbage/308261 to your computer and use it in GitHub Desktop.
Autocompleter.implement({
choiceOver: function(choice, selection){
if (!selection && this.options.forceSelect) this.selectedValue = this.opted = choice.inputValue;
return this.parent.apply(this, arguments);
},
hideChoices: function(clear){
if (clear && this.options.forceSelect && (!this.visible || !this.selected) && this.element.value != this.opted) {
this.opted = "";
this.fireEvent('onEmptySelect', [this.element]);
}
return this.parent.apply(this, arguments);
},
onCommand: function(e) {
if (e && e.key && !e.shift && e.key == 'enter' && this.options.forceSelect && !this.typeAhead && this.selected && this.visible)
this.element.value = this.opted;
return this.parent.apply(this, arguments);
},
markQueryValue: function(str) {
return this.options.filterSubset == 'word' ?
str.replace(new RegExp('(\\b' + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>')
: this.parent(str);
}
});
/*
new Autocompleter.Ajax.Json(
id,
'/AutoComplete.ashx',
{
minLength: 1,
width: 420,
selectFirst: true,
forceSelect: true,
selectMode: 'pick',
filterSubset: 'word',
postVar: 'User',
injectChoice: function(json)
{
var choice = new Element('li', { html: this.markQueryValue(json.value) });
choice.inputValue = json.value;
choice.userID = json.id;
this.addChoiceEvents(choice).inject(this.choices);
},
onSelect: function(element, selected){
mySelectedID = selected.userID;
},
onEmptySelect: function(){
mySelectedID = null;
}
}
);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment