jQuery UI autocomplete display configurations -
i new jquery ui autocomplete, there way can configure input when people input label, corresponding values show selection? far can make people select other labels using {label:"label1", value:"value1" ...}.
i want have input accepts label , pop appropriate values selection.
thanks
i found solution problem here code
<!doctype html> <html> <head lang="en"> <meta charset="utf-8"> <title></title> <script src="js/jquery.js"></script> <link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.4.custom.css"/> <script src="js/jquery-ui-1.10.4.custom.js"></script> </head> <body> <script> $(function(){ var labels = ["cg", "ai", "cv", "rmi", "je", "ji", "ja"]; var values = ["computer graphics", "artificial intelligence", "computer vision", "remote method invocation", "java - elementary", "java - intermediate", "java - advanced"] $(".tags").autocomplete({ source : function(req, response){ var reg = $.ui.autocomplete.escaperegex(req.term); var matcher = new regexp("^"+reg, "i"); var d = []; var = $.grep(labels, function(item, index){ var found = matcher.test(item); if(found){ d.push(values[index]); } return found; }); response(d); } }); }); </script> <input type="text" class="tags"/> </body> </html>
Comments
Post a Comment