Download
Demo
- Overview
- Documents
User Rating: 3.7/5 ( 4 votes)
Your Rating:
JQuery Autocomplete plugin is a lightweight simple and easy in settings autocomplete like Google
sex shop sex shop sex shop sex shop sex shop seks shop spanish fly psikolog sohbet numara sohbet hatti
Source: xdsoft.net
1. INCLUDE CSS AND JS FILES
<link type="text/css" rel="stylesheet" href="autocomplete.css"/> <script src="jquery.min.js"></script> <script src="autocomplete.js"></script>
2. HTML
<input type="text" placeholder="Enter state" autocomplete="off">
3. JAVASCRIPT
var states = [ 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming' ]; $(function() { $("input").autocomplete({ sources:[states] }); });
4. OPTIONS
Name | default | Ex. |
---|---|---|
valueKey | 'value' | |
The key for the identification field of the object, which contains the value | ||
titleKey | 'title' | {titleKey:'value'} |
The key for the identification field of the object, which contains the suggestion's label | ||
highlight | true | |
highlight the matching parts of words | ||
showHint | true | |
Show prompts behind the input field | ||
dropdownWidth | "100%" | {dropdownWidth:'auto'} |
Width for dropdown list | ||
dropdownStyle | {} | {dropdownStyle:{background:'red', color:'#fff', width:'500px'} |
Custom style for dropdown list | ||
itemStyle | {} | {itemStyle:{background:'red', color:'#fff', width:'500px'} |
Custom style for dropdown list element | ||
hintStyle | false | {hintStyle:{background:'red'} |
When plugin inits, style for "Hint" element takes from input element. All style's field copy to "Hint" element, but you can add custom style to "Hint". It will be combined with the copied style | ||
style | false | {style:{background:'red'} |
Plugin wraps input element in DIV box. For it is possible to set a custom style | ||
openOnFocus | true | |
Open dropdown list after focus in input | ||
closeOnBlur | true | |
Close dropdown list after blur from input | ||
autoselect | false | |
When element lost focus and nothing was selected take first element from suggestions | ||
limit | 20 | |
How many suggestions will be shown in drop-down list | ||
source | [] |
{ source:[ // local ['Alpha', 'Beta', 'Gamma'], // custom function function( q,add ){ add(['Delta','Epsilon','Zeta','Eta']); }, // local like object { data:['Theta','Iota','Kappa'] }, // dinamic from local server { url:"/?task=demodata&q=%QUERY%", type:'remote' }, // preload data from local server { url:"/?task=demodata&q=will", type:'remote' }, // dinamic request from remote // server through JSONP { url:"/test.php?query=%QUERY%", type:'remote', ajax:{ dataType : 'jsonp' } } ] } |
Source for suggestions, can be array or object or function. | ||
replace | function | |
Function compiles a URL address for AJAX request. Default
function( url,query ){ return url.replace('%QUERY%',encodeURIComponent(query)); } |
||
render | function | |
Function item renderer. Default
function( item,source,pid,query ){ var value = item[this.valueKey], title = item[this.titleKey]; return '<div '+(value==query?'class="active"':'')+ ' data-value="'+ encodeURIComponent(value)+'">'+ title+ '</div>'; } |
||
preparse | function | |
Custom manipulate with data. Default
function(items){ return items; } |
||
valid | function | |
Checks the suitability of a particular item, the current query. Default
function ( value,query ){ return value.toLowerCase().indexOf(query.toLowerCase())!=-1; } |
||
filter | function | |
Filter source's data. Default
function ( items,query,source ){ var results = [],value = ''; for(var i in items){ value = items[i][this.valueKey]; if( this.valid(value,query) ){ results.push(items[i]); } } |
||
equal | function | |
Method to search equal values. Default
function( value,query ){ return query.toLowerCase()==value.substr(0,query.length).toLowerCase(); } |
||
findRight | function | |
Method to search for an item whose value will be placed in the Hint. Default
function(items,query,source){ var results = [],value = ''; for(var i in items){ value = items[i][this.valueKey]; if( this.equal(value,query,source) ){ return items[i]; } } return false; } |
5. AJAX
<script> $('#remote_input').autocomplete({ valueKey:'title', sources:[{ url:"/component/jquery_plugins/?task=demodata&q=%QUERY%", type:'remote' }] }); $('button#open').click(function(){ $('#remote_input').trigger('open'); $('#remote_input').focus(); }); </script>