Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 85b2084

Browse files
committed
fix(select): double array issue with multislect and jQuery
1 parent 13b21aa commit 85b2084

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/widget/select.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,8 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
243243
widget.$apply(function() {
244244
var optionGroup,
245245
collection = valuesFn(modelScope) || [],
246-
key = selectElement.val(),
247246
tempScope = inherit(modelScope),
248-
value, optionElement, index, groupIndex, length, groupLength;
247+
key, value, optionElement, index, groupIndex, length, groupLength;
249248

250249
if (multiple) {
251250
value = [];
@@ -257,13 +256,15 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
257256

258257
for(index = 1, length = optionGroup.length; index < length; index++) {
259258
if ((optionElement = optionGroup[index].element)[0].selected) {
259+
key = optionElement.val();
260260
if (keyName) tempScope[keyName] = key;
261-
tempScope[valueName] = collection[optionElement.val()];
261+
tempScope[valueName] = collection[key];
262262
value.push(valueFn(tempScope));
263263
}
264264
}
265265
}
266266
} else {
267+
key = selectElement.val();
267268
if (key == '?') {
268269
value = undefined;
269270
} else if (key == ''){

test/widget/selectSpec.js

+21
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,27 @@ describe('select', function() {
591591
browserTrigger(select, 'change');
592592
expect(scope.selected).toEqual([scope.values[0]]);
593593
});
594+
595+
it('should select from object', function() {
596+
createSelect({
597+
'ng:model':'selected',
598+
'multiple':true,
599+
'ng:options':'key as value for (key,value) in values'
600+
});
601+
scope.values = {'0':'A', '1':'B'};
602+
603+
scope.selected = ['1'];
604+
scope.$digest();
605+
expect(select.find('option')[1].selected).toBe(true);
606+
607+
select.find('option')[0].selected = true;
608+
browserTrigger(select, 'change');
609+
expect(scope.selected).toEqual(['0', '1']);
610+
611+
select.find('option')[1].selected = false;
612+
browserTrigger(select, 'change');
613+
expect(scope.selected).toEqual(['0']);
614+
});
594615
});
595616
});
596617
});

0 commit comments

Comments
 (0)