0

Trying to get Select2 to remove an item and figure out why it keeps adding a new tag on update.

Using Select2.JS V3.5

Followed ActiveAdmin / Select2 example

When I try to delete an item, it does not remove it. It also ends up combining the tag list to a new STRING creating a new tag. i.e. If I have ["play", "doe"] and I update another field, it creates a new tag called "play doe" resulting in ["play", "doe", "play doe"]. This continues every time I update.

Here's my JS code

// Generated by CoffeeScript 1.9.3
$(document).ready(function() {
 $('.tagselect').each(function() {
   var placeholder, saved, url;
   placeholder = $(this).data('placeholder');
   url = $(this).data('url');
   saved = $(this).data('saved');
   $(this).select2({
     tags: true,
     placeholder: placeholder,
     minimumInputLength: 3,
     allowClear: true,
     multiple: true,
     debug: true,
     initSelection: function(element, callback) {
       saved && callback(saved);
     },
     ajax: {
       url: url,
       dataType: 'json',
       data: function(term) {
         return {
           q: term
         };
       },
       results: function(data) {
         return {
           results: data
         };
       }
     },
     createSearchChoice: function(term, data) {
       if ($(data).filter((function() {
            return this.text.localeCompare(term) === 0;
             })).length === 0) {
            return {
              id: term,
              text: term
            };
          }
        }
      });
    });
  });
pcasa
  • 3,640
  • 7
  • 37
  • 66

1 Answers1

0

Saw https://github.com/mbleigh/acts-as-taggable-on/issues/676

adding the block in my model, fixes the formtastic bug where all tags where coming in as a flat string vs a comma separated string. Monkey Patch for now.

class MyModel < ActiveRecord::Base
  ...
  def tag_list
    super.to_s
  end
end
pcasa
  • 3,640
  • 7
  • 37
  • 66