-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ngModel formatter function removes initial values #192
Comments
Can you setup a Plunker so I can check and try to fix if it's a bug? |
Yes, 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! |
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. |
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> |
Same problem. |
@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) |
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 |
Any updates? I would really like to use the enchanchement..... |
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!
The text was updated successfully, but these errors were encountered: