Trying to use angular ui-select2 in tag mode (not simple tag), losing objects
Asked Answered
R

2

6

I've recently upgraded from angular 1.1.4 up to 1.2.9, and grabbed the latest ui-select2 directive and the latest select2 component. My select2s in tag mode have stopped working. The options list and typeahead work, but when I select anything from it, the new tag shows up as a blank thing with no value, and debugging it, I see it is getting sliced from {text: "foo", id: 10} just down to 10 - the object is being replaced with the id. I'd really appreciate any insight on why this is happening.

Demo: http://plnkr.co/edit/RepMSFQsIPDuPTNFWKUN?p=preview

Here are my select2 options:

.controller('AppController', function($scope) {
  availableTags = [
    {text: 'Apple', id: 1},
    {text: 'Apricot', id: 2},
    {text: 'Avocado', id: 3},
  ];
  $scope.select2Options = {
    tags: availableTags,
    multiple: true, 
    minimumInputLength: 1,
    formatResult: function (item) {
        return item.text;
    },
    formatSelection: function (item) {
        return item.text;
    },
  }
Rad answered 25/1, 2014 at 7:0 Comment(0)
R
13

Holy cow, Matt / invinity answered my question over on github issues:

https://github.com/angular-ui/ui-select2/issues/144#issuecomment-33287882

I had this same behavior and was able to correct it by changing the input type to
"hidden". See if that works for you.

    -matt

This completely solved it.

Rad answered 25/1, 2014 at 14:40 Comment(1)
Worked for me as well. Searched for several hours for a solutions, now this is just a bug :-/Athapaskan
F
0

This certainly seems to be a version issue. I don't think that Select2 supports Angular 1.2.5. And perhaps only supports versions < 1.2.

This fork of your plunker is working (with Angular version 1.1.5).

I did nothing but change the version number.

Raising this as a bug on GitHub is the right thing to do. :)

Fablan answered 25/1, 2014 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.