Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

How can I remove a single token? #325

Open
danderson421 opened this issue Sep 28, 2017 · 2 comments
Open

How can I remove a single token? #325

danderson421 opened this issue Sep 28, 2017 · 2 comments

Comments

@danderson421
Copy link

I'm trying to use Datatables to create and remove items from a Tokenfield, the createtoken method works as expected, but the removeToken does not work. Not sure what to pass to removeToken. Any pointers would be helpful, thanks.

		$('.ui-datatable').on('click', 'tr', function() {
			if ($(this).hasClass('active')) {
				$(this).removeClass('active');
				$('#activity_contact').tokenfield('removetoken', {
					value: $(this).attr('id'),
					label: $(this).children('td').text()
				});
			}
			else	{
				$(this).addClass('active');
				$('#activity_contact').tokenfield('createToken', {
					value: $(this).attr('id'),
					label: $(this).children('td').text()
				});
			}
		});
@skydevelopers
Copy link

I had the similar problem.
I found solution by:

  1. attaching the values with the tokenfield
  2. during delete I triggered the close a tag of that value
    here is the sample code:
    for creating the tag:

<input id="filter_tags" type="text" class="form-control" />

for inserting tag with value:
$('#filter_tags').tokenfield('createToken', { value: 1, label: "foo"});

for removing the tag:
$("*[data-value="1"]").find('a').trigger('click');

it worked properly for me.
hope it helps

@danderson421
Copy link
Author

It's been a while, but i think I just missed the case when I called the function "removeToken'.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants