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

Populate multiple select #333

Closed
jgoux opened this issue Oct 22, 2014 · 16 comments
Closed

Populate multiple select #333

jgoux opened this issue Oct 22, 2014 · 16 comments

Comments

@jgoux
Copy link

jgoux commented Oct 22, 2014

Hi,
I serialized a form to be able to reload it when needed.
All the single select are repopulated, but not the multiple select, even if the $scope is populated.
Here is a plunker with my issue : http://plnkr.co/edit/vL9L2XWeziTPuX4KxwmP?p=preview (select people in the first input then click "copy selected people")

EDIT : Better example here : http://plnkr.co/edit/vL9L2XWeziTPuX4KxwmP?p=preview

@benjamin-mueller
Copy link

same here, well .. I think it is the same problem

the ui-select possible values is populated by an async load (angular resource). if you then load the selected values asynchronous or even have them in your $scope the ng-mode for that ui-select is "null"

this never happend in ui-select2, switching back since this completly breaks all the code

@mastilver
Copy link

here's a working version: http://plnkr.co/edit/R4nFkdZsyrMhCMdSgXNc?p=preview

notice:

$scope.load = function(people) {
    $scope.form.selectedPeopleCopy = people;
  };

@jgoux
Copy link
Author

jgoux commented Oct 22, 2014

@mastilver The angular.copy was intended, because the selected data comes from an external source and is not related to the current datalist in the $scope.
This is a better example : http://plnkr.co/edit/vL9L2XWeziTPuX4KxwmP?p=preview
As you can see, the single select is populated, even if the data comes from an external source. But not the multiple select.

There is also another problem, if you try to select a person in the multiple select and then click on the button, the multiple select becomes empty.

@adamkarl-zywave
Copy link

I was able to work around this by populating my selection array using items from the choices array. Painful and costly if you have many choices but it does work.

@mastilver
Copy link

here's a working plunker of @adamkarl-zywave workaround:
http://plnkr.co/edit/dEEdWJ?p=preview

btw, I think this issue is related to the issue I opened earlier: #332

@bashanam
Copy link

my workaround for the problem:

answer is in my directive's scope (transferred to model)

var optionDic = [];
angular.forEach(/* place old answer array here ! , */ function(item) {
    optionDic[item.optionID] = item;
});

function updateAnswer(previous) {
    scope.question.answer = [];
    angular.forEach(previous, function(prevAnswer) {
        var option = optionDic[prevAnswer.optionID];
        if (!angular.isUndefined(option)) {
            scope.question.answer.push(option);
        }
    });
}

var unbindWatch = scope.$watch('answer', function(newval) {
    if (angular.isArray(newval) && newval.length > 0) {
        unbindWatch();
        updateAnswer(angular.copy(newval));
    }
}, true);

@antony
Copy link

antony commented Nov 16, 2014

In my own code, even if I use a button to re-populate the scoped object, it still doesn't work.

I think I might switch to ui-select2 as well, as this issue is just one of a good number of really broken things with this select. Echoing out the model in the html shows that it is populated as expected - really not sure what to do here!

Update: I nested my model retrieval within my async choices retrieval and before either of these called, intialised my model to {} which seems to have fixed it. It appeared that the ui-select was binding to its own copy of the model initially otherwise. Not sure if that's an angular weirdness or a ui-select weirdness but it seems to be working ok now

@stevehu
Copy link

stevehu commented Nov 17, 2014

@bashanam, could you please post a plunker demo for your solution? I am assuming your code is in a controller but I am not sure. Thanks.

@ahmer-yasin
Copy link

i have one issue when i save data in db it save objectc in array for using ui select
but i retrive the data it will never selected how can i fix it

@stevehu
Copy link

stevehu commented Jan 19, 2015

I need more context info to fully understand your question. However I guess what you sent to the server and what you retrieved from the server are different. 

Thanks,

Steve

Sent from Samsung Mobile

-------- Original message --------
From: ahmer-yasin [email protected]
Date:01-19-2015 10:04 AM (GMT-05:00)
To: angular-ui/ui-select [email protected]
Cc: stevehu [email protected]
Subject: Re: [ui-select] Populate multiple select (#333)
i have one issue when i save data in db it save objectc in array for using ui select but i retrive the data it will never selected how can i fix it


Reply to this email directly or view it on GitHub.

@ahmer-yasin
Copy link

this is point to select plan it will save but when i want to edit plan i m retriving data
data is retrive but it will not show selected

{{$item.name}}

{{p.name}}

@ahmer-yasin
Copy link

let me show you screen shot for code

@ahmer-yasin
Copy link

the problem is not for saving and retriving
problem is to show data already selected

@ahmer-yasin
Copy link

<ui-select multiple
                              ng-model="consultation.consultation_plan"
                              id="consultation_plan"
                              theme="select2"
                              ng-disabled="disabled"
                              style="width: 100%;">
                     <ui-select-match placeholder="Select plano...">{{$item.name}}</ui-select-match>
                     <ui-select-choices repeat="p in plan | filter:$select.search">
                      {{p.name}}
                      </ui-select-choices>
                     </ui-select>

@stevehu
Copy link

stevehu commented Jan 20, 2015

I have record a short video to show you have angular-schema-form-ui-selet
behaves in my framework and I cannot find what is the issue in your code as
we are using it in different ways. You can always dig into my code to
figure out how it works in schema form.

http://youtu.be/lz8fPcY_VJY

Thanks,

Steve

On Mon, Jan 19, 2015 at 10:18 AM, ahmer-yasin [email protected]
wrote:

the problem is not for saving and retriving
problem is to show data already selected


Reply to this email directly or view it on GitHub
#333 (comment)
.

@PowerKiKi
Copy link

Should be solved via #256

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants