You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
ngModel formatter function removes initial values #192
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.
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.
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.
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-selectstyle="display: block;" multipleng-model="$parent.tqModel"><ui-select-matchplaceholder="Namen eingeben...">{{$item.Vorname}} {{$item.Nachname}}</ui-select-match><ui-select-choicesrepeat="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>
@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.
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.
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
Activity
[-]ngModel formatter function removes current values[/-][+]ngModel formatter function removes initial values[/+]dimirc commentedon Sep 12, 2014
Can you setup a Plunker so I can check and try to fix if it's a bug?
mpolichette commentedon Sep 16, 2014
Yes,
http://plnkr.co/edit/Nm4dSdmIXLV2EQlA00Wx?p=preview
This plunker shows the issue. As you can see in the
demo.jsfile, I've added a few extra strings,[..., 'Car', 'Charlotte', 'Miami']to the initial$scope.multipleDemo.colorsarray. However, those values are not present in the$scope.availableColorsarray, 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!
wald-tq commentedon Sep 18, 2014
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.
wald-tq commentedon Sep 18, 2014
At the moment I am using following workaround:
link-function from my select directive:
template:
call to the directive:
Yankovsky commentedon Oct 15, 2014
Same problem.
tradiff commentedon Nov 5, 2014
@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)
baumandm commentedon Nov 19, 2014
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.
zukasmichael commentedon Feb 14, 2015
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
arnoudhgz commentedon Apr 3, 2015
Any updates? I would really like to use the enchanchement.....