jquery - Tokenizer plugin with autocomplete. Do I implement it properly? -
i using plugin found here - http://www.jqueryscript.net/form/simple-jquery-tagging-tokenizer-input-with-autocomplete-tokens.html
github - https://github.com/firstandthird/tokens dependecies - https://github.com/jgallen23/fidel
example uses: 1) working example (source array loaded in memory) - http://jsfiddle.net/george_black/brmbyl8x/
js code:
(function () { $('#tokens-example').tokens({ source: ['acura', 'audi', 'bmw', 'cadillac', 'chrysler', 'dodge', 'ferrari', 'ford', 'gmc', 'honda', 'hyundai', 'infiniti', 'jeep', 'kia', 'lexus', 'mini', 'nissan', 'porsche', 'subaru', 'toyota', 'volkswagon', 'volvo'], initvalue: ['acura', 'nissan'] }); })(); html code:
<h2>cars</h2> <input type="text" id="tokens-example" /> and works properly.
2) faulty configuration example? (source array generated server , loaded ajax, not actually, idea )- http://jsfiddle.net/george_black/xamxryn6/
function testfunctionfeed(query){ //dynamic results server return ['acura', 'audi', 'bmw', 'cadillac', 'chrysler', 'dodge', 'ferrari', 'ford', 'gmc', 'honda', 'hyundai', 'infiniti', 'jeep', 'kia', 'lexus', 'mini', 'nissan', 'porsche', 'subaru', 'toyota', 'volkswagon', 'volvo']; } (function () { $('#tokens-example').tokens({ initvalue: ['acura', 'nissan'], query: function(query,callback){ //show query $("#loggerquery p").text(query); //let's results dynamic server var sgstions = testfunctionfeed(query); console.log(sgstions); $("#loggercallback p").text(sgstions); callback(sgstions); } }); })(); but here following error in console:
uncaught typeerror: cannot read property 'suggestions-list-element' of undefined in tokens' github page can read config use in second example.
"query": function used retreive suggestions. default, use internal sources, can write own function query database , return array of suggestions. function receives 2 parameters query : value entered user callback : function should call, passing suggestions array, once finished getting results my question is, did use plugin in second example? has else used specific tokenizer plugin?
tokens has exact behaviour want tokenizer plugin (custom tags, autocomplete functionality, easy theming etc.) , use ajax call.
i got answer 1 of plugin's developers.
in not working example, calling callback function out of scope (keep in mind had no samples begin with). below correct code.
working example - http://jsfiddle.net/george_black/vx8dnggh/
(function () { $('#tokens-example').tokens({ initvalue: ['acura', 'nissan'], query: function(query,callback){ //show query $("#loggerquery p").text(query); //let's results dynamic server var sgstions = testfunctionfeed(query); callback.call(this, sgstions); } }); })();
Comments
Post a Comment