Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

ngModel formatter function removes initial values #192

Open

Description

@mpolichette

This could be a quick answer.

Is it be design that the formatter function will remove (not show in UI) values which may be on the model array, if they're not provided in the ui-select-choices?

The way I'm using ui-select, sometimes I will have some initial selected tags which are not present in the select choices. This is ok for my data, however, the formatter will remove them and never show them. It will also force them out of the model the first time it updates $modelValue.

If this is by design, ok. :(
Otherwise this is a bug report/feature request. :) and I would be happy to chip in some time and work on solving it.

Thanks for the cool project!

Activity

  1. changed the title [-]ngModel formatter function removes current values[/-] [+]ngModel formatter function removes initial values[/+] on Sep 12, 2014
  2. dimirc commented on Sep 12, 2014

    @dimirc

    Can you setup a Plunker so I can check and try to fix if it's a bug?

  3. mpolichette commented on Sep 16, 2014

    @mpolichette
    Author

    Yes,
    http://plnkr.co/edit/Nm4dSdmIXLV2EQlA00Wx?p=preview
    This plunker shows the issue. As you can see in the demo.js file, I've added a few extra strings, [..., 'Car', 'Charlotte', 'Miami'] to the initial $scope.multipleDemo.colors array. However, those values are not present in the $scope.availableColors array, and therefore are not rendered in the ui-select.

    Granted, those are not colors, :P, but they are present values in the initial array.

    Being that displaying values is a separate task from validation, I would think it would be fine to render values which are not part of the select choices.

    This will especially be an issue when considering the possible feature of allowing select choices as well as free-form text entry.

    Let me know what you think!

  4. wald-tq commented on Sep 18, 2014

    @wald-tq

    I think I have a issue which is related to this.

    I get a initial value from a ngResource and assign it via ng-model to the ui-select. The ui-select uses a refresh method to fetch the items from a server.

    Now the items in ng-model are not in the initial array returned by the server as I am filtering server side.

    The difference to the issue from @mpolichette is that I am using Objects instead of strings.

  5. wald-tq commented on Sep 18, 2014

    @wald-tq

    At the moment I am using following workaround:

    link-function from my select directive:

    dir.link = function ($scope: tqAnsprechpartnerSelectMultipleDirectiveScope) {
    
        $scope.items = [];
    
        $scope.$watch('tqModel', function (newValue, oldValue) {
            if (newValue === oldValue) {
                return;
            }
    
            if ($scope.tqModel.length > 0) { 
                // we have to add the items from the tqModel to the items.
                // see: https://github.com/angular-ui/ui-select/issues/192
                $scope.items = $scope.items.concat($scope.tqModel);
            }
        });
    
        $scope.refresh = function (name) {
            $scope.items = tqAnsprechpartner.searchByNameAndFirma({query: name});
        };
    }

    template:

    <ui-select style="display: block;" multiple ng-model="$parent.tqModel">
        <ui-select-match placeholder="Namen eingeben...">{{$item.Vorname}} {{$item.Nachname}}</ui-select-match>
        <ui-select-choices repeat="item in items"
                           refresh="refresh($select.search)"
                           refresh-delay="500">
            <div>{{item.Vorname}} {{item.Nachname}}</div>
            <small>
                <strong>{{item.Name_1}}</strong>
            </small>
        </ui-select-choices>
    </ui-select>

    call to the directive:

    <tq-ansprechpartner-select-multiple style="display: block;" tq-model="tempEditValue"></tq-ansprechpartner-select-multiple>
  6. Yankovsky commented on Oct 15, 2014

    @Yankovsky

    Same problem.

  7. tradiff commented on Nov 5, 2014

    @tradiff
    Contributor

    @dimirc Can you confirm that you consider this to be an issue, and not by design? This is a problem for my project in which I am wanting to initialize the control with some values that were selected in a previous session. The list of options is initially empty because I'm querying a rest api based on user input.

    User @reifi has a solution to this which he mentioned in #294 (a duplicate of this issue)

  8. baumandm commented on Nov 19, 2014

    @baumandm

    I ran into this issue too, using multiple and "refresh" to dynamically load choices based on a search string. I need ui-select to keep previously-selected items in the model, even when doing a different search.

    The workaround of adding the items in the model to the choices array seems to be working OK.

  9. zukasmichael commented on Feb 14, 2015

    @zukasmichael

    is there any updates for this issue ? I'm working on one project now who could have thousands of tags and I can only load them on search pattern so preloading object tags in this case becoming an issue

  10. added this to the 0.10.x milestone on Feb 14, 2015
  11. arnoudhgz commented on Apr 3, 2015

    @arnoudhgz

    Any updates? I would really like to use the enchanchement.....

  12. removed this from the 0.10.x milestone on Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions