Mar 07 2010

Meio.Autocomplete – A Mootools Autocomplete Plugin

fabiomcosta @ 18:17

Download and documentation:

Meio.Autocomplete on Github

44 Responses to “Meio.Autocomplete – A Mootools Autocomplete Plugin”

  1. Kevin says:

    Very nice Autocomplete class!! I want to use it in a JSR-168 portlet, and want to use the portlet namespace as part of the CSS container class (to avoid collisions with other CSS classes on the page). I set the listOptions.classes.container but it was not working. I put some logging in the code, and the List.render() function was happening BEFORE the list.initialize, and I realized it was because List.initialize() was calling this.parent() before it called this.setOptions(options). I needed to change the code, so that it called this.setOptions(options) FIRST, and then called this.parent() (which caused the List to render).

  2. Pedro Martins says:

    Nice work, Fábio!

    Abraço ;-) Pedro Martins

  3. Hugh Messenger says:

    Hey Fabio, good work.

    Does this rely on Moo 1.2.4, or do you think it would work on 1.2.0?

    I’m a Joomla extension developer, where we are stuck in 1.2.0 land for a while longer …

    – hugh

  4. Javier says:

    hey good code! congratulations! a question: which version of 1.2.4 or 1.2.1 works m00tools? I work with 1.2.1 and MochaUI

  5. Ahmad says:

    Hey Fabio. Could you completeled the “Meio.Autocomplete.Select with a URL (It will make Ajax requests to the passed URL)”?, the demos not clear thanks

  6. frlobe says:

    Hello Fabio, nice plugin. As it works with Mootool, is there any possibility to make it work inside Joomla? Thank you in advance

  7. Racheal Hauan says:

    ohhhh nice…cool..awesome..how can describe the beauty of this images…fantastic,thanks dear,congratulations man

  8. atkins food list phase 2 says:

    I found your website via google thanks for the post. I will bookmark it for future reference.

  9. codedigger says:

    The demos on your page are showing errors. Some problem with your server? Would love to see it working.

  10. zalun says:

    MooShell has been switched off without warning – jsFiddle is not responsible for this. I’m working on the issue and I will try to make them woerk as soon as on jsFiddle.

    Thanks for using them, apologies for the inconvenience

  11. irfan ahmed says:

    Meio.Autocomplete.Select with a URL

    how the json data must be sent from the server to display the result as autocomplete (not the local data example)

    for this code ?

    new Meio.Autocomplete.Select('field', 'search.php', {
    syncName: false, valueField: $('value-field'), valueFilter: function(data){ return data.identifier; }, filter: { type: 'contains', path: 'text' } });

    Thanks & regards Irfan Ahmed

  12. irfan ahmed says:

    if you can provide me PHP server script example that would be great for sending json response

  13. irfan ahmed says:

    i am using joomla with mootools upgraded plugin

  14. Oskar Krawczyk says:

    Hey Fabio, you’re fiddles are outdated – they don’t work since 1.2.x is selected instead of 1.3.

  15. fabiomcosta says:

    Updated the fiddles, thanks again @Oskar!

  16. Autocomplete plugin for mootools | Shadow Blog says:

    [...] recently building a app i was need to suggest data to the user when trying to fill a input. so i look for a js script for this. i usually use mootools for my development in js, so looking for a plugin i found this: Meio.Autocomplete plugin for mootools [...]

  17. Looc says:

    Hi! This plugin looks realy nice, nut i´m missing one multiple – to split the user entered text into multiple values;

    Nice to be used in a email client, so if i search for on address first, then after entering ; i just search for the second value and so on..

  18. Phill says:

    How can I set it to use POST instead of GET?

    Ive set it to use a URL

    I would like to send the queryVarName parameter as POST

    Cheers

  19. fabiomcosta says:

    hmm it’s not possible right now, but im marking this so i can add it on the next release

  20. Lex says:

    Hi Fabio, great script and work, many thanks.

    Could you give an example of the Autocompleter thay sends a GET request to database query page (php page for example) and then returns results for “data” variable please?

    I have over 10,000 records which I import locally from a PHP script but it is too heavy for the page.

    I can do the PHP no problem, I just don’t have the expertise to do the Javascript.

    Thanks in advance!

  21. Alex says:

    Olá Fabio! Baixei o código e não consegui fazer rodar o autocomplete fica dando um erro que “Meio is undefined” tem alguma biblioteca a mais daquelas do demo que tem que incluir ?

    Obrigado! Alex.

  22. AHHP says:

    Hi, This plugin is very buggy while using AJAX and server-side value checking: 1. “Success” Event of Request.JSON in Meio.Autocomplete.Data.Request::createRequest is never run! It seems MooTools bug; anyway I changed Request.JSON to Request and it’s solved. 2. Plugin uses GET method and i did many changes to pass extraParams as POST values. I think that it should be optional! 3. Meio.Autocomplete::refreshCache never runs in plugin and the cache is never emptied, i always get first result set and second request is never sent so i appended “&rand=(new Date()).getTime()” to request URL. 4. Meio.Autocomplete.Filter::_getValueFromKeys makes error while options.path is not set so method below returns input object so i added a new line to it: _getValueFromKeys: function(obj, keys){ // keys is [""] when options.path is not set var key, value = obj; if(keys.length==1 && keys[0]==”") return obj.value; // Added by me for (var i = 0; key = keys[i++];) value = value[key]; return value; }

    It will be a great plugin if you debug it. Thanks AHHP

  23. AHHP says:

    Hi,

    Another problem, It requests empty fields too! i add a line to Meio.Autocomplete.Data.Request::prepare to prevent it:

    if(!text || text==”") return;

    I’m sorry for my bad reports but i think reports may make it perfect…

  24. virtualgadjo says:

    hi,

    nice plugin, too bad, i can’t have it work with ajax. With a local array it works lie a charm with ajax, i can see the response in firebug but apparently the plugin doesn’t read it (even exactly the same object hardcoded in the ajax called url) i’m stuck :) but will find out a salvage solution with an array…

  25. virtualgadjo says:

    hi again, just for you to know, this line throws an error in IE 7&8

    if (this.node) this.node.set(‘autocomplete’, ‘on’); line 589

    commenting it doesn’t prevent the script from working and doing what the comment says it should do

    Have swing

  26. Barry Beanie says:

    I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here frequently. I am quite sure I will learn plenty of new stuff right here! Good luck for the next!

  27. fabiomcosta says:

    That’s awesome Nestor! thanks for sharing!

  28. Stan says:

    Hi, well, great plugin, and I got it worked fine with ajax. No worries there. There’s just one more thing I need to do : after a result has been selected, I need to clear the autocomplete field to be able to start a new search. Tried to just clear the field’s value but it’s not enough. How do I completely reset the thing ?

  29. Mootools Autocomplete says:

    [...] Meio I cannot get to work with a url/json request. it is throwing a strange test is not a function error. [...]

  30. Goran says:

    Hello!

    Fantastic code! Thanks for sharing. I’m a bit of a beginner with JS and mootools, so please accept apologies if this is a silly question: I’m trying to get it work with a backend PHP script which gets data from a db (instead of hard-coded var):

    I’ve got it to work as far as sending the request to the backend, but it’s not processing the response correctly. Here’s the code:

    new Meio.Autocomplete.Select('field', 'localhost/ac/', { valueFilter: function(data){ return data.identifier; }, requestOptions: { method: 'get', formatResponse: function(response){ var data = []; new JSON.decode(response).each(function(identifier, item){ this.include({value: identifier, text: item.text}); }, data); return data; } }, ...

    And the PHP pseudocode:

    loop for all like '%abc%' { $a = array('identifier'=>0, 'item'=>$row["term"]); array_push ($result, $a); } print json_encode($result);

    I’m not getting any errors in js console, etc, so I’m a little stumped and would appreciate any assistance.

    Thank you so much!

  31. Goran says:

    Tweaked the code a bit:

    formatResponse: function(response){ var data = []; new response.each(function(identifier, item){ this.include({value: identifier, text: item.text}); }, data); return data; }

    using a JS debugger, I can see that the response variable receives the correct data from the backend, but the data variable is not being populated with identifier/item values.

    Sorry, I know this is wrong forum, but would appreciate any help.

  32. Goran says:

    Solved!

    requestOptions: { method: 'get', formatResponse: function(response){ var data = []; response.each(function(obj) { this.include({identifier: obj.id, value: obj.descr}); }, data); return data; } },

  33. Henry says:

    Hi,

    Great contribution, thanks!

    I’m wondering though: how can I get something like onChange=”this.form.submit()” to work with this autocomplete system? ie, if the user clicks with mouse or selects with keyboard one of the autocomplete options, I’d like the Submit button to be fired automatically (the way google does on their search box).

    Since onChange=”this.form.submit()” is actually for a tag, how can this be achieved when this autocompleter uses a tag instead?

    I’d appreciate any comments.

    Thanks

  34. Henry says:

    sorry, your form ate my tags:

    Since onChange=”this.form.submit()” is actually for an select tag, how can this be achieved when this autocompleter uses an input tag instead?

  35. Sergey says:

    Hello. I want to ask you, how can i move focus from autocomplete input to another element on the page after any item from autocomplete list is selected? Event “onSelect” doesn’t help me in this purpose.

  36. Sergey says:

    Done. Overloaded setInputValue in my own class like this:

    setInputValue: function(){ this.parent(); this.fireEvent(‘afterSelect’); }

    And then defined onAfterSelect function:

    onAfterSelect: function(){ this.elements.field.node.blur(); myElement.focus(); }

  37. Douglas Machado says:

    I get a $(document.body) is null on line 718. Line 718 Contents: $(document.body).grab(node);

    How do I fix this? I’m using MooTools version 1.3.2

    Best regards,

  38. Douglas Machado says:

    Any idea on how to ignore accented characters. A real life example: A user searches for the word “Grafica” and there is a result “Gráfica” but it is not displayed because in theory it does not match, however I need to be a valid match;

    Thanks in advanced for your help.

  39. Cla says:

    Great plugin! But I have a problem with “Meio.Autocomplete.Select with a URL”; Ajax call returns a correct json, but I don’t see the list; div.ma-container ul is always empty!

  40. Douglas Machado says:

    Great software. Thanks for sharing. Question: - How can I disable the cache? I’ve tried to set cacheLength to 0, but it does not clear the cache.

    Thanks again.

  41. mickey mouse waffle maker says:

    Read carefully below so that you know exactly what time the items that you want are going to go on sale. Waffle Maker Cooking - Believe it or not waffle makers can make more than just waffles. For scrambled eggs, add the eggs to the pie iron and close, holding over the campfire until eggs are done.

Leave a Reply