fabiomcosta / mootools-meio-autocomplete

A complete mootools Autocomplete plugin
http://www.meiocodigo.com/projects/meio-autocomplete/
32 stars 14 forks source link

Meio.Autocomplete - Copyright (c) 2010 Fábio Miranda Costa

Meio.Autocomplete - a mootools plugin for creating autocomplete fields.

Screenshot

Introduction

This plugin creates an autocomplete list of options at the bottom of an input text or textarea element. The list can be any other container that you like too. See the demos to understand it better. Please don't hesitated to ask anything. Feel free.

Dependencies

Meio.Autocomplete depends on Mootools-more Element.Forms. It's included into the "/Assets" folder. There's also a "BGIFrame.js" port into the "/Source" folder for solving the z-index issues with select and object elements on IE6. You just need to include it into your page for it to work together with Meio.Autocomplete. It's completely optional.

Note

1.x and below are the versions made to be used with Mootools 1.2.x. 2.x and greater are the versions made to be used with Mootools 1.3.x or greater.

How to use

This example shows most of its this plugin's options. All the values are the default ones.

#JS
var data = [
    {"value": 0, "text": "Brazil"},
    {"value": 1, "text": "Ajax"},
];

var autocomplete = new Meio.Autocomplete(
    document.id('text_input_id'),
    data // can be an array
         // or an url (a JSON request will be created
         // or a function that should provide the data (see examples inside the documentation)
);

Demos

Meio.Autocomplete.Select with a local Array

http://jsfiddle.net/fabiomcosta/eZpuL/1229/

Meio.Autocomplete.Select with a URL (It will make Ajax requests to the passed URL)

http://jsfiddle.net/fabiomcosta/rrBnB/31/

Meio.Autocomplete.Select with a local Array and using accent folding

http://jsfiddle.net/fabiomcosta/FP9FA/10/

Meio.Autocomplete.Select.One

http://jsfiddle.net/fabiomcosta/EC5D2/13/

Meio.Autocomplete.Select with the same Meio.Element.List instance

http://jsfiddle.net/fabiomcosta/wz84W/7/

API Docs

Class: Meio.Autocomplete

Implements:

Options, Events.

Syntax:

var myAutocomplete = new Meio.Autocomplete(element, data [, options, listInstance]);

Arguments:

Options:

Events:

onNoItemToList

Fires onkeypress while there are no options to list.

Arguments:
onSelect

Fires when you select an autocomplete option.

Arguments:
onDeselect
Arguments:

Class: Meio.Autocomplete.Select

This class does exactly what Meio.Autocomplete does plus it can easy act as a DOM select element, putting the 'value' attribute of it's options into a form field (which will be called valueField). It can synchronize its value with the valueField ondomready of the page, working perfectly when the field comes pre-filled with a text value (like on an edit form).

Extends:

Meio.Autocomplete

Syntax:

var mySelectAutocomplete = new Meio.Autocomplete.Select(element, data [, options]);

Arguments:

Options:

Credits

Inspiration and some ideas came from:

Changelog

2.0.1
2.0
1.0
0.8.5
0.84
0.83
0.82
0.81

License

The MIT License (http://www.opensource.org/licenses/mit-license.php)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.