Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
    },
  }
like image 997
Michael Natkin Avatar asked Jan 25 '14 07:01

Michael Natkin


1 Answers

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.

like image 137
Michael Natkin Avatar answered Oct 19 '22 23:10

Michael Natkin