javascript - jQuery Multiple AutoCompletes -


i'm using jquery ui autocomplete, on page i've got 3 inputs put autocomplete on i'm trying handle so:

    var elem = $('.tags');      var groups = ["c","c++","java","javascript","php","python","ruby"];     var users = ["john doe","jane doe","jim doe"];     var ips = ["test1","test2","test3"];      elem.autocomplete({         source:  elem.attr('data-remote-source').split(','),     }); 

but not working me, doing wrong in code?

the html code follows:

<input type="search" name="" data-remote-source="groups" class="tags" placeholder="search groups" />  <input type="search" name="" data-remote-source="users" class="tags" placeholder="search users" />  <input type="search" name="" data-remote-source="ips" class="tags" placeholder="search ips" /> 

elem.attr('data-remote-source') returning string 'groups'

the reason returning same string elem global (outside autocomplete initializer) , matches 3 inputs. jquery returning first match.

then trying split string @ commas, returning [ "groups" ]

here demo of - 3 autocompletes match 'groups' , nothing else: http://jsfiddle.net/86y2w/

here's fix:

var elem = $('.tags');  var data = {     "groups": ["c","c++","java","javascript","php","python","ruby"],     "users": ["john doe","jane doe","jim doe"],     "ips": ["test1","test2","test3"] };  elem.each(function(i,e){     $(e).autocomplete({         source:  data[$(e).attr('data-remote-source')]     }); }); 

this uses string (for example groups) lookup actual array data variable

heres same fiddle, updated code: http://jsfiddle.net/86y2w/1/


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -