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

NgModel modes. #126

Closed
Closed

Description

@the-spyke

Is there an option to set ngModel not to a selected object, but to desired object property/item id?

Activity

  1. BaconSoap commented on Dec 19, 2013

    @BaconSoap
    Contributor

    Hi, just to clarify: you're asking if when binding select2 to an array of objects, if you can make ng-model be the selected object's id?

  2. the-spyke commented on Dec 19, 2013

    @the-spyke
    Author

    Hi, yes.

  3. bsr203 commented on Dec 20, 2013

    @bsr203

    Hi I have same/similar question. same as http://stackoverflow.com/questions/14985346/setting-initial-values-of-angular-ui-select2-multiple-directive

    What I expect is, if we feed a collection as options and and the initial selection (akin to selectedin normal select box) should be set to the current ng-model. I am not sure the initSelection is the right was as indicated in the SO post.

  4. Sharondio commented on Jan 3, 2014

    @Sharondio

    Any updates on this? I'm doing what I thought was a simple ng-model = array of selected items to initialize the select2 element, and at some point it recognizes them because the selected items are omitted from the options, but they don't show up as tags.

  5. Sharondio commented on Jan 4, 2014

    @Sharondio

    OK, got it working with the initSelection:

    initSelection : function (element, callback) {
    callback($(element).data('$ngModelController').$modelValue);
    },

    But I'm with bsr203, feels a bit hacky.

  6. fghibellini commented on Feb 21, 2014

    @fghibellini

    there is a simple_tags option that when set to true assigns the object's id instead of the object itself to the model

  7. sroe commented on Feb 27, 2014

    @sroe

    @fghibellini
    i can't find this option in select2 docs, where did you get that info?
    I've tried to set this setting but it doesn't change anything :-(.
    unbenannt
    I've bound an array with ngOptions like 'item.id as item.name for item in items' and set the ngModel to the itemId which should be selected by default...

  8. fghibellini commented on Feb 27, 2014

    @fghibellini
  9. fghibellini commented on Feb 27, 2014

    @fghibellini

    but it seems to work only when you have a multiple choice input
    see #159

  10. sroe commented on Feb 27, 2014

    @sroe

    @fghibellini simple_tags is as the name says only for tags-feature, which only gets in place when isSelect = false so the convertToAngularModel and convertToSelect2Model Functions getting called.
    This will not fix my problem :-(.
    bsr2 was having this issue with a ajax/multiple option set, so this differes from the original question by the-spike i think.
    So the solution by Sharondi is also not solving my problem becaue initSelection is not called on singleselect.
    On line 95 elm.select2('val', controller.$viewValue); is getting called which is (in my case) undefined -> which results in the output you can see in my post before. But I don't know why this is happening...
    Edit:
    Sorry line 95 is not getting called...
    Edit2:
    Okay I should read the readme carefully...:
    Working with dynamic options
    ui-select2 is incompatible with select ng-options. For the best results use option ng-repeat instead.
    Sorry for wasting your time!

  11. dfsq commented on Jun 1, 2014

    @dfsq

    Any update on that?

  12. shawn-simon commented on Sep 11, 2014

    @shawn-simon

    This is really a huge pain in the ass haha

  13. RedJandal commented on Sep 15, 2014

    @RedJandal

    I have done a pull request which fixes this issue. ng-model binds to the id returned by select2 and it also allows you to bind a property in your controller to the select2 data object using a ui-data attribute.

    Check it out and let me know what you think:
    #276

  14. snimavat commented on Dec 30, 2014

    @snimavat

    Any updates? we load select2 with ajax array of objects, but want objects id to be bound to model

  15. PowerKiKi commented on Dec 30, 2014

    @PowerKiKi
    Contributor

    This project is deprecated. Fixes and new features are very unlikel yto happen. You should instead consider a migration to ui-select.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions