Git Product home page Git Product logo

Comments (6)

timschlechter avatar timschlechter commented on August 24, 2024

I'm guessing you're trying to remove the item by passing the item's value at the 'remove' call. Now the remove tries to find the item by reference, but i think you're right. Might be a good thing to try to find by both reference and value.

from bootstrap-templates.

tdhung80 avatar tdhung80 commented on August 24, 2024

Hi Tim,

I does not work both reference and value also. Normally, we don't have same object to post it into remove method.

Problem #1: Cannot remove an object from the control

[Setup code]
var $tags = $('.tags');
$tags.tagsinput({ itemValue: 'value', itemText: 'text' });

    var item = { "value": 1 , "text": "Amsterdam", "type" : "1" };
   $tags.tagsinput('add', $item);

   $('.btn-remove').click(function() { 
          $tags.tagsinput('remove',  { "value": 1 , "text": "Amsterdam", "type" : "1" }); // does not work
          $tags.tagsinput('remove',  { "value": 1 }); // does not work
          $tags.tagsinput('remove',  1 ); // does not work
          $tags.tagsinput('remove', item); // seems to work, but it requires me to create variable to keep the same object reference, not much useful.
   });

As checking the code, i think the remove function should remove item with the same value instead of checking objects equally by === operator.

Problem #2: I could add duplicated item (object mode) into the control. IMHO, the control should ignore this if it's not in multiple mode.

My Best,
Hung Tran

from bootstrap-templates.

timschlechter avatar timschlechter commented on August 24, 2024

I fixed these issues in latest release (0.3.0). You should now be able to pass the following as argument to remove a tag:

  • exact same object instance as was added, or
  • other object instance, but wih the same value, or
  • just a value

All 3 scenario's should work.

I also made sure you can just set 1 tag when using a <select /> without multiple. When trying to add a new tag, it removes the one allready set.

Take a look at commit a319af5 for more details. Let me know if you run into any problems.

from bootstrap-templates.

tdhung80 avatar tdhung80 commented on August 24, 2024

hi Tim,

I have tested all the cases, they are worked perfectly. However, it would be more flexible if i can receive my item which i put into remove method (like i can get the same item when i put it into add method).

var myItem1 = { value: 1, text: 'text 1' };
$tagsInput.add(myItem1);
At itemAdded event, i can get the same reference as what i put into add method (myItem1).

var myItem2 = { value: 1, context: 'gridAction' };
$tagsInput.remove(myItem2);
At itemRemoved event, it returns myItem1 (the object added). It's more flexible if i can get myItem2 instead.

My Best,
Hung Tran

from bootstrap-templates.

timschlechter avatar timschlechter commented on August 24, 2024

Seems a good idea, perhaps providing both is even bettter:

self.$element.trigger($.Event('itemRemoved', { item: item, originalItem: originalItem }));

In which 'item' is the item you passed as an argument, and 'originalItem' is the instance acutally removed from the input.

from bootstrap-templates.

michaelDotco2 avatar michaelDotco2 commented on August 24, 2024

I had a similar problem, the item variable was a number but wasn't removing the item.
However i found it worked with JSON.stringify(item);

from bootstrap-templates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.