JSFiddle - React, Tailwind, and code Playground
by gagan
HTML
<input type="text" id="as-input-025" autocomplete="off" class="as-input">
CSS
/* AutoSuggest CSS - Version 1.2 */
ul.as-selections {
list-style-type: none;
border-top: 1px solid #888;
border-bottom: 1px solid #b6b6b6;
border-left: 1px solid #aaa;
border-right: 1px solid #aaa;
padding: 4px 0 4px 4px;
margin: 0;
overflow: auto;
background-color: #fff;
box-shadow:inset 0 1px 2px #888;
-webkit-box-shadow:inset 0 1px 2px #888;
-moz-box-shadow:inset 0 1px 2px #888;
}
ul.as-selections.loading {
background-color: #eee;
}
ul.as-selections li {
float: left;
margin: 1px 4px 1px 0;
}
ul.as-selections li.as-selection-item {
color: #2b3840;
font-size: 13px;
font-family: "Lucida Grande", arial, sans-serif;
text-shadow: 0 1px 1px #fff;
background-color: #ddeefe;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ddeefe), to(#bfe0f1));
border: 1px solid #acc3ec;
border-top-color: #c0d9e9;
padding: 2px 7px 2px 10px;
border-radius: 12px;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
box-shadow: 0 1px 1px #e4edf2;
-webkit-box-shadow: 0 1px 1px #e4edf2;
-moz-box-shadow: 0 1px 1px #e4edf2;
}
ul.as-selections li.as-selection-item:last-child {
margin-left: 30px;
}
ul.as-selections li.as-selection-item a.as-close {
float: right;
margin: 1px 0 0 7px;
padding: 0 2px;
cursor: pointer;
color: #5491be;
font-family: "Helvetica", helvetica, arial, sans-serif;
font-size: 14px;
font-weight: bold;
text-shadow: 0 1px 1px #fff;
-webkit-transition: color .1s ease-in;
}
ul.as-selections li.as-selection-item.blur {
color: #666666;
background-color: #f4f4f4;
background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f4f4f4), to(#d5d5d5));
border-color: #bbb;
border-top-color: #ccc;
box-shadow: 0 1px 1px #e9e9e9;
-webkit-box-shadow: 0 1px 1px #e9e9e9;
-moz-box-shadow: 0 1px 1px #e9e9e9;
}
ul.as-selections li.as-selection-item.blur a.as-close {
...
JavaScript
/*
* AutoSuggest
* Copyright 2009-2010 Drew Wilson
* www.drewwilson.com
* code.drewwilson.com/entry/autosuggest-jquery-plugin
*
* Version 1.4 - Updated: Mar. 23, 2010
*
* This Plug-In will auto-complete or auto-suggest completed search queries
* for you as you type. You can add multiple selections and remove them on
* the fly. It supports keybord navigation (UP + DOWN + RETURN), as well
* as multiple AutoSuggest fields on the same page.
*
* Inspied by the Autocomplete plugin by: Jšrn Zaefferer
* and the Facelist plugin by: Ian Tearle (iantearle.com)
*
* This AutoSuggest jQuery plug-in is dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){
$.fn.autoSuggest = function(data, options) {
var defaults = {
asHtmlID: false,
startText: "Enter Name Here",
emptyText: "No Results Found",
preFill: {},
limitText: "No More Selections Are Allowed",
selectedItemProp: "value", //name of object property
selectedValuesProp: "value", //name of object property
searchObjProps: "value", //comma separated list of object property names
queryParam: "q",
retrieveLimit: false, //number for 'limit' param on ajax request
extraParams: "",
matchCase: false,
minChars: 1,
keyDelay: 400,
resultsHighlight: true,
neverSubmit: false,
selectionLimit: false,
showResultList: true,
start: function(){},
selectionClick: function(elem){},
selectionAdded: function(elem){},
selectionRemoved: function(elem){ elem.remove(); },
formatList: false, //callback function
beforeRetrieve: function(string){ return string; },
retrieveComplete: function(data){ return data;...