API to add/remove items #45

Closed
gshilin opened this Issue Mar 27, 2011 · 27 comments

Comments

Projects
None yet

gshilin commented Mar 27, 2011

Hi, that's the best library I've seen and is so suitable for Rails.

I've got a situation when there is a checkbox, and its status should change content of list managed by tokeninput.

I need an API to add/remove items programmatically. Something like add_item(id, name) and remove_item(id).

Thanks in advance!

marcora commented Mar 29, 2011

it would also be nice to have a remove_all() or clear() method as well.

Owner

loopj commented Apr 1, 2011

I plan on implementing these soon, thanks for the suggestion.

It would be great to have those methods (add_item, remove_item, clear) for testing. I'm currently pulling my hairs for testing a form using your great plugin.

@ghost

ghost commented Apr 14, 2011

I would love this too.

elfassy commented Apr 14, 2011

+1

elfassy commented Apr 15, 2011

adding items is a must if items are added via ajax elsewhere on the page (and thus cannot be preloaded)

Contributor

manuelbernhardt commented Apr 19, 2011

+1 for this feature as well

phlegx commented Apr 19, 2011

+1

I'd also love to see this feature implemented. It's the only thing that keeps me from starting to use this plugin.

ramigg commented Apr 26, 2011

+1 - today in order to add/remove items on the fly I have to reload it with a preloaded items and this is pain in the ass

Contributor

manuelbernhardt commented Apr 28, 2011

Since we are so many interested in this API, what about designing it a bit more in the meanwhile? :)

Following the jQuery plugin method guidelines I'd propose something along the lines of:

# add one or more tokens
$('#tokens').tokenInput('add', {id: 123, name:'foobar'});
$('#tokens').tokenInput('add', [{id: 123, name:'foobar'}, {id:456, name:'baz'}]);

# remove a token by id
$('#tokens').tokenInput('remove', {id: 123});

# remove a token by name
$('#tokens').tokenInput('remove', {name: 'foobar'});

# remove them all
$('#tokens').tokenInput('clear');

What do you think of that?

marcora commented Apr 28, 2011

Looks good to me :)

I would only add the possibility of removing multiple items by either id or
name by passing an array, like in the add method.

Just my two cents,

Edoardo

On Thu, Apr 28, 2011 at 12:34 PM, manuelbernhardt <
reply@reply.github.com>wrote:

Since we are so many interested in this API, what about designing it a bit
more in the meanwhile? :)

Following the jQuery plugin method guidelines I'd propose
something along the lines of:

add one or more tokens

$('#tokens').tokenInput('add', {id: 123, name:'foobar'});
$('#tokens').tokenInput('add', [{id: 123, name:'foobar'}, {id:456,
name:'baz'}]);

remove a token by id

$('#tokens').tokenInput('remove', {id: 123});

remove a token by name

$('#tokens').tokenInput('remove', {name: 'foobar'});

remove them all

$('#tokens').tokenInput('clear');

What do you think of that?

Reply to this email directly or view it on GitHub:
#45 (comment)

Edoardo "Dado" Marcora, Ph.D.

Senior Research Fellow
California Institute of Technology
Division of Biology
Beckman Behavioral Biology Laboratories, Room 238
MC 216-76
1200 E California Blvd
Pasadena, CA 91125
USA

T: +1-626-395-3924
F: +1-626-395-8474
E: marcora@caltech.edu

W: http://marcora.caltech.edu/

Programmer
Mouse Genomics
European Bioinformatics Institute
European Molecular Biology Laboratory
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
UK

M: +44-(0)1223-96-96-13 / +39-392-990-6302
T: +44-(0)1223-494-451
F: +44-(0)1223-494-468
E: marcora@ebi.ac.uk / edoardo.marcora@gmail.com

''Sono diverso perche' sono omozigoto.''
http://marcora.caltech.edu/omozigoto.wav

vshiray commented Apr 28, 2011

+1

+1 for the whole lot.

@ghost

ghost commented May 1, 2011

$('#tokens').tokenInput('clear');

Definitely needed.

sabersd commented May 17, 2011

has anyone come up with a work around for this issue? I would like to use the plugin, but I need to be able to update the tags list from a tag cloud. I have been unsuccessful so far.

cnhzlt commented May 26, 2011

+1 for clear

rmyadsk commented Jun 1, 2011

+1 for both accessing and clearing all items (see issue #110).

pioz commented Jun 1, 2011

+1

cabgfx commented Jun 2, 2011

+1

srh5209 commented Jun 3, 2011

@sabersd: For the interim, I just do this:

// (whatever you want to trigger the action)(function() {
$('.token-input-token-facebook').remove();
});

edit---

And although it works for my circumstances, I just realized a problem...

rmyadsk commented Jun 3, 2011

@srh5209 - yes, we need a legitimate way to create, select, and destroy items in the tokenized selector. It's surprising - and disappointing - that there's no built-in public get or set accessors which will take an index integer as an argument.

How many more +1's do we really need? Is this plugin still being actively developed or is the answer in a fork or another project altogether?

t0r0 commented Jun 7, 2011

i need clear feature badly :/ is there a workaround?

I've implemented the add/remove/clear methods in my fork. It's not the most elegant solution since I was trying to change as little as possible, but hopefully others can build upon it.

7ab7e79

rmyadsk commented Jun 11, 2011

Edit - to call the clear method built by @stephhenpant, you can use:

$("#mytokenizeddivid").tokenInput("clear");

How might I pass the parameters for the add and remove methods?

It's as outlined above by @manuelbernhardt:

# add one or more tokens
$('#tokens').tokenInput('add', {id: 123, name:'foobar'});
$('#tokens').tokenInput('add', [{id: 123, name:'foobar'}, {id:456, name:'baz'}]);

# remove a token by id
$('#tokens').tokenInput('remove', {id: 123});

# remove a token by name
$('#tokens').tokenInput('remove', {name: 'foobar'});

# remove them all
$('#tokens').tokenInput('clear');
Owner

loopj commented Jun 12, 2011

Hey everyone, I've merged the work from @stephenpant into master. Huge thanks to @stephenpant and @manuelbernhardt!

loopj closed this Jun 12, 2011

I'm using ajax based search result,after no results found means i need to add with my database what i have given in token input fields.But here not able to get the values because input field was hided.Can pls some help how fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment