TextboxList meets Autocompletion
This post discusses a project which has its own page. Please refer to TextboxList for the most up-to-date information.

In my previous blogpost I explained how to extend TextboxList to add closing functionality via a link added to each box. But it was missing an important ingredient: autocompletion!
Again, all we have to do is extend the TextboxList class, override some methods, some events, and create some new ones (all prefixed by auto)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | var FacebookList = new Class({ Extends: TextboxList, data: [], options: { onInputFocus: function() { this.autoShow(); }, onInputBlur: function(el) { el.value = ''; this.autoHide(); }, onBoxDispose: function(item) { this.autoFeed(item.$attributes.$text); }, autocomplete: { 'opacity': 0.8, 'maxresults': 10, 'minchars': 1 } }, initialize: function(element, autoholder, options) { arguments.callee.parent(element, options); this.autoholder = $(autoholder).set('opacity', this.options.autocomplete.opacity); this.autoresults = this.autoholder.getElement('ul'); var children = this.autoresults.getElements('li'); children.each(function(el) { this.add(el.innerHTML); }, this); }, autoShow: function(search) { this.autoholder.setStyle('display', 'block'); this.autoholder.getElements('*').setStyle('display', 'none'); if(! search || ! search.trim() || (! search.length || search.length < this.options.autocomplete.minchars )) { this.autoholder.getElement('.default').setStyle('display', 'block'); this.resultsshown = false; } else { this.resultsshown = true; this.autoresults.setStyle('display', 'block').empty(); this.data.filter(function(str) { return str ? str.test(search, 'i') : false; }).each(function(result, ti) { if(ti >= this.options.autocomplete.maxresults) return; var el = new Element('li').set('html', this.autoHighlight(result, search)).inject(this.autoresults); el.$attributes.$result = result; if(ti == 0) this.autoFocus(el); }, this); } }, autoHighlight: function(html, highlight) { return html.replace(new RegExp(highlight, 'gi'), function(match) { return '<em>' + match + '</em>'; }); }, autoHide: function() { this.resultsshown = false; this.autoholder.setStyle('display', 'none'); }, autoFocus: function(el) { if(! el) return; if(this.autocurrent) this.autocurrent.removeClass('auto-focus'); this.autocurrent = el.addClass('auto-focus'); }, autoMove: function(direction) { if(!this.resultsshown) return; this.autoFocus(this.autocurrent['get' + (direction == 'up' ? 'Previous' : 'Next')]()); }, autoFeed: function(text) { if(this.data.indexOf(text) == -1) this.data.push(text); }, autoAdd: function(el) { if(!el || ! el.$attributes.$result) return; this.add(el.$attributes.$result); delete this.data[this.data.indexOf(el.$attributes.$result)]; this.autoHide(); this.current.$attributes.$input.value = ''; }, createInput: function(options) { var li = arguments.callee.parent(options); var input = li.$attributes.$input; input.addEvents({ 'keydown': function(e) { e = new Event(e); this.dosearch = false; switch(e.code) { case Event.Keys.up: return this.autoMove('up'); case Event.Keys.down: return this.autoMove('down'); case Event.Keys.enter: this.autoAdd(this.autocurrent); this.autocurrent = false; this.autoenter = true; break; default: this.dosearch = true; } }.bind(this), 'keyup': function() { if(this.dosearch) this.autoShow(input.value); }.bind(this) }); input.addEvent(Browser.Engine.trident ? 'keydown' : 'keypress', function(e) { if(this.autoenter) new Event(e).stop(); this.autoenter = false; }.bind(this)); return li; }, createBox: function(text, options) { var li = arguments.callee.parent(text, options); li.addEvents({ 'mouseenter': function() { this.addClass('bit-hover') }, 'mouseleave': function() { this.removeClass('bit-hover') } }); li.adopt(new Element('a', { 'href': '#', 'class': 'closebutton', 'events': { 'click': function(e) { new Event(e).stop(); if(! this.current) this.focus(this.maininput); this.dispose(li); }.bind(this) } })); li.$attributes.$text = text; return li; } }); window.addEvent('domready', function() { // init var tlist2 = new FacebookList('facebook-demo', 'facebook-auto'); // fetch and feed new Request.JSON({'url': 'json.html', 'onComplete': function(j) { j.each(tlist2.autoFeed, tlist2); }}).send(); }); |
It works by caching all the results from a JSON Request and feeding them to the autocompleter object. When a item is added as a box, it’ removed from the feed array, and when the box is disposed it’s added back, so that it becomes available in the list when the user types.
Another new feature is that you’ll be able to let it add boxes from the HTML directly:
1 2 3 4 5 6 7 8 9 | <label>FacebookList input</label> <input type="text" value="" id="facebook-demo" /> <div id="facebook-auto"> <div class="default">Type the name of an argentine writer you like</div> <ul class="feed"> <li>Jorge Luis Borges</li> <li>Julio Cortazar</li> </ul> </div> |
The constructor now takes new parameters to configure the autocompletion, like the minimum number of characters to trigger the dropdown, and more.
Changelog
- 0.1: initial release
- 0.2: added click support, removed $attributes use, code cleanup
Download
Click here to download the zip with code and examples
-
[...] Ver Demo Descargar AKPC_IDS += “1026,”; [...]
-
[...] Facebook-Like Auto Suggest [...]
-
[...] 5.) TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion « Devthought (tags: autosuggest jquery ajax javascript facebook webdesign webdev) [...]
-
[...] 5.) TextboxList meets Autocompletion [...]
-
[...] 5.) TextboxList meets Autocompletion [...]
-
[...] 5.) TextboxList meets Autocompletion [...]
-
[...] 5.) TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] por scripts en JavaScript que hagan “auto completar” me encontré con AutoCompleteList (http://devthought.com/blog/projects-news/2008/01/textboxlist-meets-autocompletion/) un excelente script que parecía cumplir con lo que yo necesitaba, hacía auto completar y además [...]
-
[...] Facebook Autocompletion [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion This is a very good feature will allows you to auto complete by putting several options in one single text box, with a added feature of cross with every value to remove if not needed. [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] TextboxList meets Autocompletion [...]
-
[...] Enlace: TextboxList meets Autocompletion [...]
-
[...] mayor información visitar la siguiente página: Web : http://devthought.com/textboxlist-meets-autocompletion/ Demo : [...]
-
[...] New! TextboxList with autocompletion [...]
-
[...] New! TextboxList with autocompletion [...]
-
[...] Facebook Style Input Box The approach to re-create the autocomplete method of adding multiple recipients to messages used on Facebook. “I’d seen it in Facebook before, which has a really decent implementation of this concept (it work well, but it doesn’t respect any modern programming principles; basically, it’s a big tag soup with lots of inline Javascript)” [...]
-
[...] Textboxlist Auto-Completion One of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X” link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. [...]
-
[...] TextboxList meets Autocompletion: giri? formlar?n?n otomatik olarak doldurulmas? için kullan?labilir. benzer bir uygulamayla ajax alan ad? arama yaz?s?nda kar??la?m??t?k. [...]
-
[...] TextboxList meets Autocompletion: giri? formlar?n?n otomatik olarak doldurulmas? için kullan?labilir. benzer bir uygulamayla ajax alan ad? arama yaz?s?nda kar??la?m??t?k. [...]
-
[...] TextboxList meets Autocompletion: giri? formlar?n?n otomatik olarak doldurulmas? için kullan?labilir. benzer bir uygulamayla ajax alan ad? arama yaz?s?nda kar??la?m??t?k. [...]
-
[...] burada 20 ajax efekti toplanm??. TextboxList meets Autocompletion: giri? formlar?n?n otomatik olarak doldurulmas? i?in [...]
-
[...] Facebook Style Input Box The approach to re-create the? autocomplete method? of adding multiple recipients to messages used on Facebook. “I’d seen it in Facebook before, which has a really decent implementation of this concept (it work well, but it doesn’t respect any modern programming principles; basically, it’s a big tag soup with lots of inline Javascript)” [...]
-
[...] mootools script that does a Facebook-like or AppleMail-like input control: thebasic one here and here with autocompletion.? The first thing I noticed is that Guillermo is only 17 years old! If you look at his original [...]
-
[...] is a chore that can easily made much more simple (and I dare say fun) with a splash of Ajax. TextboxList meets Autocompletion is one such example of an auto-complete script that takes a Facebook-esque approach to [...]
-
[...] is a chore that can easily made much more simple (and I dare say fun) with a splash of Ajax. TextboxList meets Autocompletion is one such example of an auto-complete script that takes a Facebook-esque approach to [...]
-
[...] is a chore that can easily made much more simple (and I dare say fun) with a splash of Ajax. TextboxList meets Autocompletion is one such example of an auto-complete script that takes a Facebook-esque approach to [...]
-
[...] pratica che può essere resa molto più semplice (e oserei dire divertente) con un tocco di Ajax. TextboxList è un esempio di un completamento automatico di script che prende esempio da Facebook. [...]
-
[...] Autocomplete TextboxList [...]
-
[...] Kaynak Kod || Demo Tags: ajax, autocomplete, autocompletion, css, design, devthought, facebook, ipucu, javascript, kelephir, olmazsa olmaz, otomatik, rehber, tamamlama, tasar?m, xhtml [...]
-
[...] is a chore that can easily made much more simple (and I dare say fun) with a splash of Ajax. TextboxList meets Autocompletion is one such example of an auto-complete script that takes a Facebook-esque approach to [...]
-
[...] Post Original Post Relacionados [...]
-
[...] http://devthought.com/textboxlist-meets-autocompletion/ Partilha: These icons link to social bookmarking sites where readers can share and discover new [...]
-
[...] Facebook Style Input Box The approach to re-create the autocomplete method of adding multiple recipients to messages used on Facebook. “I’d seen it in Facebook before, which has a really decent implementation of this concept (it work well, but it doesn’t respect any modern programming principles; basically, it’s a big tag soup with lots of inline Javascript)” [...]
-
[...] Textboxlist Auto-Completion One of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X” link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. [...]
-
[...] ?????????????? ????? Textboxlist Auto-Completion (?????), ?????? ????? ???? ???? ??? ?????, ?? ? ???????? [...]
-
[...] Textboxlist Auto-CompletionOne of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X†link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. [...]
-
[...] Textboxlist Auto-Completion Un atractivo efecto en JavaScript que es realmente útil para autocompletar texto y cuya referencia de uso es por ejemplo como lo hace Facebook. [...]
-
[...] Facebook Inspired Auto-Complete Form - One of the best multiple select text forms is on facebook. This post shows you how to do it. [...]
-
[...] One of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X†link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. While working on my big and exciting new project, I decided to include an input that resembles the famous Apple Mail to: textfield. I’d seen it in Facebook before, which has a really decent implementation of this concept (it work well, but it doesn’t respect any modern programming principles; basically, it’s a big tag soup with lots of inline Javascript) http://devthought.com/textboxlist-meets-autocompletion/ [...]
-
[...] Textboxlist Auto-Completion One of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X†link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. [...]
-
[...] Textboxlist Auto-CompletionOne of the most attractive features of JavaScript is the highly useful autocompletion. No other website does the autocompletion better than Facebook. They have created an elegant way to search for other Facebook users using the autocomplete feature. Once the user is found, their name is added with an outline and an “X” link to remove the name. TextboxList has mimicked this feature and created a little script for downloading. [...]
[...] 5.) TextboxList meets Autocompletion [...]