Skip to content

Commit 91f9a83

Browse files
committed
MOBILE-1966 multipleselect: Load selected options
1 parent 8c7dd65 commit 91f9a83

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

www/core/directives/multipleselect.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ angular.module('mm.core')
5353
strSeparator = $translate.instant('mm.core.elementseparator') + " ";
5454

5555
scope.optionsRender = [];
56-
scope.selectedOptions = "";
56+
scope.selectedOptions = getSelectedOptionsText();
5757

5858
element.on('click', function(e) {
5959
e.preventDefault();
@@ -81,24 +81,31 @@ angular.module('mm.core')
8181
});
8282

8383
scope.saveOptions = function() {
84-
var selected = [];
8584
angular.forEach(scope.optionsRender, function (tempOption){
8685
for (var j = 0; j < scope.options.length; j++) {
8786
var option = scope.options[j];
8887
if (option[keyProperty] == tempOption.key) {
8988
option[selectedProperty] = tempOption.selected;
90-
if (tempOption.selected) {
91-
selected.push(tempOption.value);
92-
}
9389
return;
9490
}
9591
}
9692
});
97-
scope.selectedOptions = selected.join(strSeparator);
93+
scope.selectedOptions = getSelectedOptionsText();
9894

9995
scope.closeModal();
10096
};
10197

98+
// Get string for selected options to be shown.
99+
function getSelectedOptionsText() {
100+
var selected = scope.options.filter(function(option) {
101+
return !!option[selectedProperty];
102+
}).map(function(option) {
103+
return option[valueProperty];
104+
});
105+
106+
return selected.join(strSeparator);
107+
}
108+
102109
scope.closeModal = function(){
103110
scope.modal.hide();
104111
};

0 commit comments

Comments
 (0)