TextboxList meets Autocompletion

TextboxList Autocompletion

Demo here

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)

Click here to see Javascript code

  1. var FacebookList = new Class({
  2.  
  3. Extends: TextboxList,
  4.  
  5. data: [],
  6.  
  7. options: {
  8. onInputFocus: function() { this.autoShow(); },
  9. onInputBlur: function(el) {
  10. el.value = '';
  11. this.autoHide();
  12. },
  13. onBoxDispose: function(item) {
  14. this.autoFeed(item.$attributes.$text);
  15. },
  16. autocomplete: {
  17. 'opacity': 0.8,
  18. 'maxresults': 10,
  19. 'minchars': 1
  20. }
  21. },
  22.  
  23. initialize: function(element, autoholder, options) {
  24. arguments.callee.parent(element, options);
  25. this.autoholder = $(autoholder).set('opacity', this.options.autocomplete.opacity);
  26. this.autoresults = this.autoholder.getElement('ul');
  27. var children = this.autoresults.getElements('li');
  28. children.each(function(el) { this.add(el.innerHTML); }, this);
  29. },
  30.  
  31. autoShow: function(search) {
  32. this.autoholder.setStyle('display', 'block');
  33. this.autoholder.getElements('*').setStyle('display', 'none');
  34. if(! search || ! search.trim() || (! search.length || search.length < this.options.autocomplete.minchars ))
  35. {
  36. this.autoholder.getElement('.default').setStyle('display', 'block');
  37. this.resultsshown = false;
  38. } else {
  39. this.resultsshown = true;
  40. this.autoresults.setStyle('display', 'block').empty();
  41. this.data.filter(function(str) { return str ? str.test(search, 'i') : false; }).each(function(result, ti) {
  42. if(ti >= this.options.autocomplete.maxresults) return;
  43. var el = new Element('li').set('html', this.autoHighlight(result, search)).inject(this.autoresults);
  44. el.$attributes.$result = result;
  45. if(ti == 0) this.autoFocus(el);
  46. }, this);
  47. }
  48. },
  49.  
  50. autoHighlight: function(html, highlight) {
  51. return html.replace(new RegExp(highlight, 'gi'), function(match) {
  52. return '<em>' + match + '</em>';
  53. });
  54. },
  55.  
  56. autoHide: function() {
  57. this.resultsshown = false;
  58. this.autoholder.setStyle('display', 'none');
  59. },
  60.  
  61. autoFocus: function(el) {
  62. if(! el) return;
  63. if(this.autocurrent) this.autocurrent.removeClass('auto-focus');
  64. this.autocurrent = el.addClass('auto-focus');
  65. },
  66.  
  67. autoMove: function(direction) {
  68. if(!this.resultsshown) return;
  69. this.autoFocus(this.autocurrent['get' + (direction == 'up' ? 'Previous' : 'Next')]());
  70. },
  71.  
  72. autoFeed: function(text) {
  73. if(this.data.indexOf(text) == -1)
  74. this.data.push(text);
  75. },
  76.  
  77. autoAdd: function(el) {
  78. if(!el || ! el.$attributes.$result) return;
  79. this.add(el.$attributes.$result);
  80. delete this.data[this.data.indexOf(el.$attributes.$result)];
  81. this.autoHide();
  82. this.current.$attributes.$input.value = '';
  83. },
  84.  
  85. createInput: function(options) {
  86. var li = arguments.callee.parent(options);
  87. var input = li.$attributes.$input;
  88. input.addEvents({
  89. 'keydown': function(e) {
  90. e = new Event(e);
  91. this.dosearch = false;
  92. switch(e.code) {
  93. case Event.Keys.up: return this.autoMove('up');
  94. case Event.Keys.down: return this.autoMove('down');
  95. case Event.Keys.enter:
  96. this.autoAdd(this.autocurrent);
  97. this.autocurrent = false;
  98. this.autoenter = true;
  99. break;
  100. default: this.dosearch = true;
  101. }
  102. }.bind(this),
  103. 'keyup': function() {
  104. if(this.dosearch) this.autoShow(input.value);
  105. }.bind(this)
  106. });
  107. input.addEvent(Browser.Engine.trident ? 'keydown' : 'keypress', function(e) {
  108. if(this.autoenter) new Event(e).stop();
  109. this.autoenter = false;
  110. }.bind(this));
  111. return li;
  112. },
  113.  
  114. createBox: function(text, options) {
  115. var li = arguments.callee.parent(text, options);
  116. li.addEvents({
  117. 'mouseenter': function() { this.addClass('bit-hover') },
  118. 'mouseleave': function() { this.removeClass('bit-hover') }
  119. });
  120. li.adopt(new Element('a', {
  121. 'href': '#',
  122. 'class': 'closebutton',
  123. 'events': {
  124. 'click': function(e) {
  125. new Event(e).stop();
  126. if(! this.current) this.focus(this.maininput);
  127. this.dispose(li);
  128. }.bind(this)
  129. }
  130. }));
  131. li.$attributes.$text = text;
  132. return li;
  133. }
  134.  
  135. });
  136.  
  137. window.addEvent('domready', function() {
  138. // init
  139. var tlist2 = new FacebookList('facebook-demo', 'facebook-auto');
  140.  
  141. // fetch and feed
  142. new Request.JSON({'url': 'json.html', 'onComplete': function(j) {
  143. j.each(tlist2.autoFeed, tlist2);
  144. }}).send();
  145. });

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:

Click here to see HTML code

  1. <label>FacebookList input</label>
  2. <input type="text" value="" id="facebook-demo" />
  3. <div id="facebook-auto">
  4. <div class="default">Type the name of an argentine writer you like</div>
  5. <ul class="feed">
  6. <li>Jorge Luis Borges</li>
  7. <li>Julio Cortazar</li>
  8. </ul>
  9. </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

118 Responses to “TextboxList meets Autocompletion”

  1. 1
    Facebook Tarzı Dinamik Input - katodivaihe Says:

    [...] input’un aynısını yapmış. Gayet kullanılşı olmuş. Hatta başka bir örneğinde, bunu autocomplate özelliği ile de birleştirmiş ve tadından yenmez bir web kontrolüne [...]

  2. 2
    David Says:

    This is brilliant.

    Very slick and it seems to just work like you’d expect… Very neat, this definately has lots of potential.

  3. 3
    Fanciest Javascript Autocompletion! Says:

    [...] read more | digg story [...]

  4. 4
    Ahmed Says:

    thanks for such cool thing!

  5. 5
    TextboxList + Autocomplete, los textbox del iPhone en tu web | aNieto2K Says:

    [...] Guillermo me avisa de que ha terminado la versión con automplete de TextBoxList. [...]

  6. 6
    Sanallinkler Bilgi Arşivi » Blog Archive » Facebook Tarzı Dinamik Input Says:

    [...] input’un aynısını yapmış. Gayet kullanılşı olmuş. Hatta başka bir örneğinde, bunu autocomplate özelliği ile de birleştirmiş ve tadından yenmez bir web kontrolüne [...]

  7. 7
    Jacob Says:

    Of course the next step is to allow AJAX submissions for items not in the autocomplete list (on enter key).

    Looks awesome!

  8. 8
    Nuri Akman Says:

    Very useful and smart autocompletion! Simple to implement !

    But, How can I catch selected items after submitting form?

  9. 9
    Guillermo Rauch Says:

    @Nuri
    Call the update function when you submit your form.

  10. 10
    James Pearson Says:

    Very nice, I almost included it in my project away.

    But it doesn’t seem to work when you click on one of the names in the drop down list, only when you use press enter. (Firefox 2.11, Windows XP)

    Is this on purpose or something that was overlooked?

  11. 11
    Devthought - Guillermo Rauch’s Blog » TextboxList: Fancy Facebook-Like dynamic inputs! Says:

    [...] New! TextboxList with autocompletion [...]

  12. 12
    Guillermo Rauch Says:

    @James
    It actually took me longer to post the update than to code it itself… I’ve just uploaded it for you to use it in your project !

  13. 13
    Ali Pour Zahmatkesh Says:

    its very nice components with mooTools!
    nice and very nice;)

  14. 14
    Nick Says:

    Very nice - exactly what I’ve been looking for

    I am trying to use this with an ajax response (so names are pulled in from db - any tips on how to do this would be a great help.

    Thanks again

    Nick

  15. 15
    Guillermo Rauch Says:

    @Nick
    This already works with an ajax -ajaj really, the last j being of json- response

  16. 16
    Nick Light Says:

    Yeh I thought it would - but can’t seem to get the autocomplete to list the items in the json.html file….. only the two listed initially

    “Jorge Luis Borges
    Julio Cortazar”

    Thanks

    Nick

  17. 17
    Richard’s Blog » Blog Archive » Javascript for Beginners Says:

    [...] How to create a Facebook Textbox List with auto-compeltion  [...]

  18. 18
    HiTMaN Says:

    This tool is GREAT!!!

    I’m using it in my site, excellent stuff. thank you very much

    [note] for other who’s going to use this, there’s a bug with the mootools function .removeClass(’classname’) ; which doesn’t work in IE7 as far as i know.
    simply change to .className = ”;

    i’m still trying to figure out how i can set some of this options, only if there were example.

  19. 19
    sdor Says:

    I’m having the same problem as “Nick” (two posts above). I can’t get the json file to load. Everything looks same as site example. Just to be safe, I copied site JS and replaced in my JS file to no relief. Any thoughts?

    Thanks.

    p.s. Very cool. Just need it to work for me :-)

  20. 20
    Guillermo Rauch Says:

    Guys: if json.html doesn’t work for you, change the url to something that does. Remember it’s only intended as an example.

  21. 21
    Renjith Says:

    Very Nice One..
    I integrated it with PHP
    The auto sujjest is working..
    But i hav a doubt
    how to submit the data??
    sujjested result it is not in the text box

  22. 22
    Guillermo Rauch Says:

    @Renjith
    Use the .update() method of your TextboxList instance when submitting the form.

  23. 23
    Ignacio Says:

    Che, buenísimo esto, yo tambien soy de Argentina, me parece que acá esta el talento!

  24. 24
    Zach Says:

    Still cant get the update to fire. New to javascript

  25. 25
    Ninja Says:

    Had to create the instance outside the addEvent

    var tlist2 = MsgFriendsList;

    window.addEvent(’domready’, function() {
    // init
    tlist2 = new MsgFriendsList(’MESSAGEToUser’, ‘MsgFriends-auto’);

    Changed the the update function to update a hidden input

    update: function() {
    $(’MESSAGEToNames’) = this.bits.getValues().join(this.options.separator);
    //this.element.set(’value’, this.bits.getValues().join(this.options.separator));
    // return this.bits.getValues().join(this.options.separator);
    },

    and then just called the tlist2.Update() in my forms onsubmit

    I might of been wrong to do it this way, but it works

  26. 26
    Ninja Says:

    Missed out a .value after the $(’MESSAGEToNames’)

    Now it works

  27. 27
    Ignacio Says:

    I’m looking this script for only Autocompletion, without the multiple select. But no other, I want THIS script. Any help? Thanks! I’m desperate!

  28. 28
    Guillermo Rauch Says:

    @Ignacio
    It’s not worth using this script only for autocompletion.

  29. 29
    Ignacio Says:

    Thats ok, but the idea is use both, with a true or false, with multiple selects and without, you know what I mean

  30. 30
    Guillermo Rauch Says:

    @Ignacio
    In that case, a good idea would be to add an option to limit the number of boxes you can add. I’ll probably add it soon

  31. 31
    Ignacio Says:

    Thanks

  32. 32
    Nick Says:

    hello

    I have changed the url many limes in test.js - - i keep getting the same error “j has no properties
    [Break on this error] j.each(tlist2.autoFeed, tlist2);”

    Please help

  33. 33
    EGBlue Says:

    Nick, I’m having the exact same problem. it occurs because it cannot seems to open json.html, so it cannot iterate through the values. I’m not proficient with Mootools so i don’t really know how things work over there, i’m a Prototypejs guy. I was hoping somebody who is more knowledgeable with Mootools could elaborate more.
    Thanks
    - EGBlue

  34. 34
    Foxinni - Wordpress Designer Says:

    Wicked. Have been looking for something like this. Saving it to my delicious right now!

  35. 35
    nicefella Says:

    hi,

    this is very cool. but it didn’t work for me either although i simply uploaded the sample code to one of my hosting directories.
    it doesn’t seem to fetch the items from json.html.
    all i get are:
    “Jorge Luis Borges
    Julio Cortazar”

    is this a hosting-related problem?
    does this application require any other software to be installed before?

    any help?
    thanks.

  36. 36
    nicefella Says:

    @nicefella

    ok. i fixed the problem by changing the name of json.html with json.asp and test.html with test.asp

    now,

    can s.o describe how i am going to use this “update” function to catch the items selected in the textboxlist.?

  37. 37
    Best of Ajax, Dhtml and Javascript- part1 Says:

    [...] TextboxList meets Autocompletion-Using autosuggest/autocomplete in a search field to allow users add or remove terms using Mootools [...]

  38. 38
    Ozkan Says:

    I first tried the original code itself and then Ninja’s method, but, no luck.. I can’t get the values.. Any ideas..?

    P.S: I am using ASP.NET & C#

  39. 39
    xavo Says:

    In ie7 it’s a error.

    When you put 2 letters in a text see the next error:

    The objecto not accept de property ot method.

    Thank u and excuse my poor english.

  40. 40
    EGBlue Says:

    I was able to get it working simply by renaming the file from json.html to json.php, similar to nicefella’s method. Make sure you put it on your server or localhost. My suggestion is, since it acts like a dropdown select, in the JSON to have Title, and Value. they don’t have to be the same. So when clicked .update() you get the values, while the Titles are those that being displayed on the actual list.

  41. 41
    Ozkan Says:

    @EGBlue, can you send me the working sample code?
    ozkana {at] gmail (dot} com

  42. 42
    EGBlue Says:

    @Guillermo Rauch
    Do you mind if i’ll start on the process of translating your code into Prototype?
    Since Prototype is not compatible with Mootools, I cannot use your script, I really like it though and already have ‘pimped’ it.
    I would like to know if I can translate it into Prototype, commenting that it is based on your script of course.
    Thanks
    - EGBlue

  43. 43
    sapporo Says:

    @EGBlue

    If you have successfully translated the nice guillermo code into prototype, you re welcome

    thanks

    sapporro (at] gmail (dot] com

  44. 44
    Ajax Araçları : vBMaster.Org Seo Yarışması Says:

    [...] 20) TextboxList meets Autocompletion-Using autosuggest/autocomplete in a search field to allow users add or remove terms using Mootools Library. [...]

  45. 45
    danny Says:

    very nice autocomplete.

    how can i get more than one autocomlete field on a single page to work? i cant get it.
    thx

  46. 46
    Proto!TextboxList meets Autocompletion | InteRiders Says:

    [...] is the Prototype version of the extended script by Guillermo Rauch. As with the previous script, this script has been converted and operates like the original. An [...]

  47. 47
    EGBlue Says:

    Hey guys, for those who are interested. A ported version of this great script into PrototypeJS can be found at http://www.interiders.com

  48. 48
    Ajaxian » Facebook Style Input Box Says:

    [...] Rauch set out to build something similar and he did a very good job of mimicking this behavior using MooTools v1.2: While working on my big and exciting new project, I decided to include an input that resembles the [...]

  49. 49
    flipthefrog Says:

    When running it locally, i get this error on test.js, line 170

    j has no properties

    running it on apache works

  50. 50
    Revolutions Shout Box » Blog Archive » Facebook Style Input Box Says:

    [...] Rauch has built a very useful input box script for easily adding multiple recipients for messaging purposes. Utilizing Mootools v1.2 it is only [...]

  51. 51
    noisylime » Blog Archive » TextboxList meets Autocompletion Says:

    [...] LINK [...]

  52. 52
    Marcel Says:

    Pretty slick… it’s missing some of the features of the Facebook control, though:
    - When you hit the up and down arrows in your, you’re not canceling the event, so your cursor moves around in the text box
    - Facebook’s searching is done with a binary search, you’re using a sequential search… you may notice some slow down after like 5000 elements
    - Facebook’s version will give you a scrollbar if more than 10 results come back. You can even hit the down arrow with nothing typed in, and it will give you the whole list. The results are rendered on a timeout so it remains quick and responsive even when enumerating thousands of results.

    I’m impressed, though!

  53. 53
    Javascript News » Blog Archive » Facebook Style Input Box Says:

    [...] Rauch set out to build something similar and he did a very good job of mimicking this behavior using MooTools v1.2: While working on my big and exciting new project, I decided to include an input that resembles the [...]

  54. 54
    Guillermo Rauch Says:

    @Marcel
    Really interesting suggestions.. I guess I’ll have to release a new version then !
    Thanks

  55. 55
    AXXT - Web development and more » Give you input fields Facebook look Says:

    [...] here is the author page http://devthought.com/textboxlist-meets-autocompletion/ [...]

  56. 56
    Devalnor Says:

    Hi,

    I like your code style : var that = this;

    ;-)

    Anyway thanks for this. It’s a very nice one. I’ll adapted it to accept new values with other css classname for them.

    I’ll keep you in touch.

    Devalnor

  57. 57
    Weekend Links - FancyZoom, Icon Design, PHP Desktop Applications, PHP Geocoding Using Google Maps API, LinkedIn, TextboxList AutoCompletion Says:

    [...] http://devthought.com/textboxlist-meets-autocompletion/ addthis_url = ‘http%3A%2F%2Fdavidwalsh.name%2Ffancy-zoom-icon-design-php-desktop-application-php-geocoding-google-maps-api-linkedin-autocomplete%2F’; addthis_title = ‘Weekend+Links+-+FancyZoom%2C+Icon+Design%2C+PHP+Desktop+Applications%2C+PHP+Geocoding+Using+Google+Maps+API%2C+LinkedIn%2C+TextboxList+AutoCompletion’; addthis_pub = ”; [...]

  58. 58
    EGBlue Says:

    @Marcel
    Nice suggestions. How exactly can you employ Binary Search though in that kind of script?
    Let’s say you sort it by first name, and using Binary Search you are able to find the first name. Then you use that index to start a sequential search from that point on? Assuming you figure that out, how do you then use it for Last name?
    Obviously such a solution would be great, i’m just not sure how it can be employ.
    Thanks in advanced.

  59. 59
    SiNi Daily » Blog Archive » Facebook Style Input Box Says:

    [...] Guillermo Rauch set out to build something similar and he did a very good job of mimicking this behavior using MooTools v1.2: [...]

  60. 60
    Facebook style inputs :: Jaz-Lounge « Says:

    [...] just read about an autocompletion input mechanism in mootools like that used in facebook. This is a really cool way to add names from a list to your query or [...]

  61. 61
    fedi Says:

    very nice script.

    However, I am trying to insert the selected options into the DB and can’t get it work. What do I need to do?

    working with php/mysql

    thanks in advance

  62. 62
    Brian Says:

    I still can’t figure out how to pull values using the update function.

    I set the onsubmit=”tlist2.update()” for a button in my form, but it doesn’t do anything. It seems to be something simple that I’m missing. Could anybody please shed some light?

  63. 63
    Opeyemi Obembe Says:

    The autocomplete is a very wonderful tool. However, the problem is adding a value that does not exist in the autocomplete list to the input box. if for example Im using it for a intramail whereby users can send mails to each other within a site and the autocomplete lists out users who are already in the member’s friend list, what happens if he also wants to send to a member who is not in his friend’s list? I was thinnking thst typing in the value and pressing enter will do the trick but it doesnt. Tested on IE7 and Opera9

  64. 64
    Bobby Says:

    I have the same issue like Brian. However, it seems there is no support or advice here. If someone of you knows the answer could you please help us. I believe many people here have the same problem.

  65. 65
    ian Says:

    i tired using the update function, it works for default values, but after trying to input something, list2.bits gets whatever was in the autocomplete list, instead of what is in the textboxlist. Any solution?

  66. 66
    ian Says:

    nevermind i got update to work.

  67. 67
    Jan Says:

    Does anyone have an example of how to use update function (new to java…). Any example will do, I’m sure I can figure it out, just don’t know where to start on this one.
    Thanks!

  68. 68
    Jan Says:

    Hey All,
    Love the script. Yet, I have a problem. I am new to Java and I have no idea how to ‘call the update()’ function, does anyone have an example of how this is done? Sure I can figure it out if I just can see how it’s done.

    Thanks!

  69. 69
    CSSgallery.info » ajax autosuggest or autocomplete Says:

    [...] TextboxList meets Autocompletion [...]

  70. 70
    Best Of February 2008 | Best of the Month | Smashing Magazine Says:

    [...] Facebook Style Input BoxThe 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)” [...]

  71. 71
    Best Of February 2008 | Best of the Month | Smashing Magazine Says:

    [...] Facebook Style Input BoxThe 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)” [...]

  72. 72
    sanath Says:

    Hi I am very much interested in this work . I am from a java background and we use DWR not JSON(and I am not familiar with JSON ). I need to understand this piece of code that I have pasted here.

    new Request.JSON({’url’: ‘json.html’, ‘onComplete’:

    I have also downloaded the sample demo and found that it contained a file named “json.html’ which contained a string array. How can I integrate this with DWR? or else If I am going to use jason wuts the step that I need to take to integrate it with my code . CURRENTLY i AM GETTING THE DB DATA VIA DWR TO MY CLIENT SIDE AND I AM ABLE TO PRINT THE RELEVANT DATA USING “alerts”"”

  73. 73
    Fatih Hayrioğlu’nun not defteri » 01 Mart 2008 web’den seçme haberler Says:

    [...] Facebook benzeri otomatik tamamlama scripti. Bağlantı [...]

  74. 74
    Facebook List TextboxList with AutoCompletion | GreatSo.com Says:

    [...] an input that resembles the famous Apple Mail to: textfield? It would be something similar to Facebook List Input. Basically, it’s a group of pieces or bits, that can be either a box or an input. The user is [...]

  75. 75
    Martin Says:

    Great script, I will for shure use it in my future projects.

  76. 76
    Mark Says:

    is there anyway to only allow only one name to be submitted, instead of an unlimited amount?

  77. 77
    facebook textboxlist — award tour Says:

    [...] Facebook TextboxList with Autocompletion. that’s a pretty good trick of having the input box inside a fake input box. [...]

  78. 78
    Magus Creo » Blog Archive » People Searchin’ Says:

    [...] YUI Autocomplete AJAX Select Drowdown with ID AutoCompleter Tutorial - jQuery(Ajax)/PHP/MySQL Yahoo! AutoComplete jQuery Autocomplete Mod FaceBoox style autosuggest with jQuery Implementing AJAX Suggest and Autocomplete Ajax autosuggest/autocomplete from database Ajax Auto Suggest v.2 Facebook List TextboxList with AutoCompletion Proto!MultiSelect 0.2 TextboxList meets Autocompletion [...]

  79. 79
    ulas Says:

    i made my own list for autocomplete, but i want that box be empty at first - how can i ?

  80. 80
    Fusion Says:

    Hi. This is wonderful stuff. I’ve used this in one of my projects and has proved a great success. But like everything, it has some issues. Here’s what it is..
    I’m updating the dropdown list, i.e. fetchfile on every keyword selection. e.g. If i search abc and get 10 results. I select one of them. Then i search again (type again). Now i’m making a new JSONString which returns say 2 results. But my drop down is showing 9 keywords options.
    In short, the issue is i want to update the drop down list on every hit. The JSONString i’m returning is updated but the drop down list is not..
    can the authors or anyone else please help me out on this.. Kinda urgent matter.
    Many thanks.

  81. 81
    NextMint Says:

    Hi,
    Could anybody post a working example of how to get the data posted? What needs to be changed, and where?

    Many thanks

  82. 82
    Korayem Says:

    mega slick…loong live ASP.NET

  83. 83
    Korayem Says:

    Oppps..ditch that asp.net part in my comment, it was a stupid copy paste error….

    Thanks for sharing, this is super cool

  84. 84
    JP! Says:

    Hello everyone!

    Where do i put the update() function!? People say they figured it out but don’t post the solution!

  85. 85
    JP! Says:

    after several hours of fustration i figured it out ! (Using ninja’s method) but it was even easier. I left the update function as is!

    // Like ninja said. Placing tlist2 outside the addEvent.
    var tlist2 = BandsList;

    window.addEvent(’domready’, function() {

    tlist2 = new BandsList(’bands’, ‘bands-auto’);

    // fetch and feed
    new Request.JSON({’url’: ‘json.php’, ‘onComplete’: function(j) {
    j.each(tlist2.autoFeed, tlist2);
    }}).send();
    });

    //// === in the HTML form ==== ///

  86. 86
    JP! Says:

    after several hours of fustration i figured it out ! (Using ninja’s method) but it was even easier. I left the update function as is!

    // Like ninja said. Placing tlist2 outside the addEvent.
    var tlist2 = BandsList;

    window.addEvent(’domready’, function() {

    tlist2 = new BandsList(’bands’, ‘bands-auto’);

    // fetch and feed
    new Request.JSON({’url’: ‘json.php’, ‘onComplete’: function(j) {
    j.each(tlist2.autoFeed, tlist2);
    }}).send();
    });

    //// === in the HTML form ==== ///
    <input type=”submit” onClick=”javascript:tlist2.update();” value=”Submit” />

  87. 87
    Will Says:

    I’m with JP. I’m not sure where to put the update function. So if someone could explain it that would great!

    Thanks.

  88. 88
    Delapouite Says:

    Here is an example code to put in the domready :

    window.addEvent(’domready’, function() {

    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();

    $(’facebook-form’).addEvent(’submit’, function(){ //facebook-form is the form id
    tlist2.update();
    })
    });

    One problem remaining on IE :
    pressing enter while the autocomplete list opened submit the form instead of just adding the list item like the Fx / Opera behavior

  89. 89
    Pablo Rey Says:

    loco, no se cuanto sabes de ajax… pero me parece que de literatura argentina sabes bastante ;)

  90. 90
    Pablo Rey Says:

    nice and usefull ;)

  91. 91
    60 More AJAX- and Javascript Solutions For Professional Coding | Developer's Toolbox | Smashing Magazine Says:

    [...] Facebook Style Input BoxThe 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)” [...]

  92. 92
    60 solutions en AJAX - BLoOgLe Says:

    [...] text : à la Facebook, ou [...]

  93. 93
    Sean O Says:

    Very Cool. Any jQuery implementation of this, or something similar?

  94. 94
    60 профессиональных AJAX и JavaScript решений Says:

    [...] Facebook Style Input Box Скрипт комбинирует метод автодополнения и добавление нескольких адресатов к сообщению, такой инструмент используется в  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)” [...]

  95. 95
    Craig Says:

    Excellent work by the way. Love it. Ive noticed though that it isnt populating any kind of hidden fields so that you can POST the information with a submit button? Is this something you are looking to add?

  96. 96
    Guillermo Rauch Says:

    @Craig
    The update() method takes care of that. You can either call it yourself or add it to the blur() method, which is what the upcoming version does (since so many people asked).
    Nice website, by the way.

  97. 97
    links for 2008-04-18 - The Boltzmann Constant Says:

    [...] TextboxList meets Autocompletion (tags: JavaScript Forms Ajax web2.0 JQuery) [...]

  98. 98
    AJAX and Javascript Solutions For Professional Coding - The Arts Lab TurkeY Says:

    [...] 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)” [...]

  99. 99
    Facebook Style Input Box - .:咸湿鱼 Says:

    [...] 一款Facebook风格的自动完成输入框 [...]

  100. 100
    webpixelkonsum Says:

    Great idea to improve the feedback for the user. Beside that thank you the possibility to get the source coude for free ;)

    Ralph

  101. 101
    fedmich Says:

    Thanks for the script :)

  102. 102
    60 More AJAX- and Javascript Solutions For Professional Coding | Web Tools | Web Design & Graphic Design Blog Says:

    [...] 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)” [...]

  103. 103
    Milestone 01 - 70+ High-End Components for Web Designers and Developers : DevKick Blog Says:

    [...] TextboxList / Mootools [...]

  104. 104
    Rainmore Says:

    That’s a great script. Thanks!!

    Well, I met a problem here that I can’t input any other name but only the name from file.

    How can I submit the name from either the list file or from the input by myself?

    Thanks for the help.

    Rainmore

  105. 105
    Rainmore Says:

    After going through all the notes, I summary some Q&A hereAfter going through all the notes, I summary some Q&A here:
    Q:The script doesn’t work on dropdown list? Or No dropdown list ?
    A: Please change the following file name to .php, .asp or .jsp rather than .html
    Eg:
    json.html ->json.php
    test.html -> test.php

    Q: Can’t upload the list?
    A: 2 steps
    1. Modify test.php (if you had change the extension of test.html) or test.html
    a. Add name and id to the form as “facebook-form”;

    b. Add name to the input where id = “facebook-demo”;

    c. Add submit button within the form

    2. Add a script to the file test.js at line 172 or add the script within the funciton window.addEvent(‘domread’,function()) as
    $(’facebook-form’).addEvent(’submit’,function(){ // facebook-form is the form id
    tlist2.update();
    })
    After the change the function should be:

    window.addEvent(’domready’, function() {
    // init
    var tlist2 = new FacebookList(’facebook-demo’, ‘facebook-auto’);

    // fetch and feed
    new Request.JSON({’url’: ‘namelist.php’, ‘onComplete’: function(j) {
    j.each(tlist2.autoFeed, tlist2);
    }}).send();

    $(’facebook-form’).addEvent(’submit’,function(){ // facebook-form is the form id
    tlist2.update();
    })
    });

    HTH!!!!

  106. 106
    antonio Says:

    For the next version it would be great if you could use a json file that has IDs associated with values, like: ["32":Sylvia Molloy","12":"Julio Cortazar".....] And store just the IDs in the input element. That would be VERY useful if you need to get the ID of the selected objects when you process the form.

  107. 107
    Alan Says:

    Will there be a version with Keyboard Support?

  108. 108
    Dynamic Form Autocomplete (Facebook Style) Says:

    [...] form autocomplete code, named TextboxList, is built on Mootools javascript framework and works just like the Facebook form inputs that are [...]

  109. 109
    Jeff Liu Says:

    Great Job!
    What is this license?

  110. 110
    Jeff Liu Says:

    Hello everyone
    Is there an article only on this cute auto-complete ?
    since i don’t need the TextboxList

  111. 111
    JAVIER MARROQUIN Says:

    I donwload the code and i have a problem with test.js
    Just change one line of code

    j.each(tlist2.autoFeed, tlist2);
    chacnge to
    var j = j.each(tlist2.autoFeed, tlist2);

  112. 112
    Imran Says:

    Hey this is really cool thanks, I will use this :)

  113. 113
    Rufus Bazley Says:

    is it possible to link this to a access db with VB script does any one know?

  114. 114
    ryan Says:

    i tried this using mootools 1.2 (non-beta) but it wasn’t working. what seems to be the problem?

  115. 115
    Hannes Says:

    Hey,

    I’m also interested in getting this thing to work with moo 1.2!
    Any plans for a soon 0.3 ?

  116. 116
    PLxKARL Says:

    I know….compatible version for 1.2 would be very nice. I LIKE !!!

  117. 117
    10 Mootools scripts for enhancing your html forms Says:

    [...] http://devthought.com/textboxlist-meets-autocompletion/ Tags: form, mootools if (typeof window.Delicious == “undefined”) window.Delicious = {}; [...]

  118. 118
    Blox.Svbasi · 60 More AJAX- and Javascript Solutions For Professional Coding Says:

    [...] 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)” [...]

Leave a Reply