Skip to content

Ui-select multiple not populating model values from async callback #86

Closed
@lopsided

Description

@lopsided

Hey,

Firstly, great plugin, thanks!

I have a situation I am loading the data and the choices for the ui-select from the server. I am using the master branch now, but I started the last tagged (0.15).

The schema:

labels: {
    type: 'array',
    items: {type: 'string'}, /// I'm using mongodb backend so the label ids are strings
    title: 'Labels'
}

The form:

{
    key: 'labels',
    type: 'uiselectmultiple',
    placeholder: 'Labels',
    options: {
        asyncCallback: function (options, filter) {
            var deferred = $q.defer();
            LabelResource.getAll({count: 99999, 'filter[name]': filter}, true).then(function (data) {
                var labels = [];
                angular.forEach(data, function (label) {
                    labels.push({
                        value: label.value,
                        name: label.name
                    });
                });
                deferred.resolve({data: labels});
            });

            return deferred.promise;
        }
    }
},

So far, so good. This populates the options for the multi-select properly and I can pick and search (with server-side filtering too which is nice).

But the problem comes with editing an existing object. The pre-selected labels don't get populated into the select. The labels property of my model looks like:

 [Object { value="56b227201fd96722d0b10799",  name="firstlabel"}, Object { value="56b227201fd96722d0b10798",  name="second label"}]

I have tried flattening this to just the values

 ["56b227201fd96722d0b10799", "56b227201fd96722d0b10798"]

but still, the select box stays empty.

I have had a good dig through the code but I'm a bit clueless where it is failing or what I'm doing wrong. I think it seems related to #43 but I think that issue (and related PR/fix) is about a single select, not multi-select.

I've inspected the $scope at this line in finalizeTitleMap:

$scope.uiMultiSelectInitInternalModel($scope.externalModel);

and I can see $scope.model contains my full model, but both $scope.internalModel and $scope.externalModel are [].

In fact, I just realised if I change this line to:

$scope.uiMultiSelectInitInternalModel($scope.model.labels);

Then it works (with the flattened list of values). Obviously that's just a hack, but does that give any clues?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions