xoxco / jQuery-Tags-Input

Magically convert a simple text input into a cool tag list with this jQuery plugin.
http://xoxco.com/projects/code/tagsinput/
2.29k stars 826 forks source link

how to get and set as objects? #319

Closed basith374 closed 8 years ago

basith374 commented 8 years ago

i've the following array:

[
    {'id':1,'name':'John'},
    {'id':2,'name':'Drew'},
    {'id':3,'name':'Alex'},
];

i need to get the names as suggestions and store them as objects in the input field so that i can later retrieve them by id. how can i do this?

speedygfw commented 8 years ago

Names are unique. So you don't should use objects in combination with tags-input.

basith374 commented 8 years ago

but the names are fetched from a database. they may not be unique. besides, i only need their id's to post the data to the server.

speedygfw commented 8 years ago

wrong behavior. you should really use tags as they are. (in this definition) a comma seperated list of strings

speedygfw commented 8 years ago

you can try to map your list with ids on clienside (even here by name ;) )

something like: (after submit, before send to server)

var tags = mytagelement.getTags();
for (x in yourobjlist)
{
     if (tags.indexOf(yourobjlist[x].name)....
    .....
    .....
}
basith374 commented 8 years ago

ok thanks for the advice