mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-11 00:03:10 +00:00
fix(select): double array issue with multislect and jQuery
This commit is contained in:
parent
13b21aaf5a
commit
85b2084f57
2 changed files with 25 additions and 3 deletions
|
|
@ -243,9 +243,8 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
|
||||||
widget.$apply(function() {
|
widget.$apply(function() {
|
||||||
var optionGroup,
|
var optionGroup,
|
||||||
collection = valuesFn(modelScope) || [],
|
collection = valuesFn(modelScope) || [],
|
||||||
key = selectElement.val(),
|
|
||||||
tempScope = inherit(modelScope),
|
tempScope = inherit(modelScope),
|
||||||
value, optionElement, index, groupIndex, length, groupLength;
|
key, value, optionElement, index, groupIndex, length, groupLength;
|
||||||
|
|
||||||
if (multiple) {
|
if (multiple) {
|
||||||
value = [];
|
value = [];
|
||||||
|
|
@ -257,13 +256,15 @@ var selectDirective = ['$formFactory', '$compile', '$parse',
|
||||||
|
|
||||||
for(index = 1, length = optionGroup.length; index < length; index++) {
|
for(index = 1, length = optionGroup.length; index < length; index++) {
|
||||||
if ((optionElement = optionGroup[index].element)[0].selected) {
|
if ((optionElement = optionGroup[index].element)[0].selected) {
|
||||||
|
key = optionElement.val();
|
||||||
if (keyName) tempScope[keyName] = key;
|
if (keyName) tempScope[keyName] = key;
|
||||||
tempScope[valueName] = collection[optionElement.val()];
|
tempScope[valueName] = collection[key];
|
||||||
value.push(valueFn(tempScope));
|
value.push(valueFn(tempScope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
key = selectElement.val();
|
||||||
if (key == '?') {
|
if (key == '?') {
|
||||||
value = undefined;
|
value = undefined;
|
||||||
} else if (key == ''){
|
} else if (key == ''){
|
||||||
|
|
|
||||||
|
|
@ -591,6 +591,27 @@ describe('select', function() {
|
||||||
browserTrigger(select, 'change');
|
browserTrigger(select, 'change');
|
||||||
expect(scope.selected).toEqual([scope.values[0]]);
|
expect(scope.selected).toEqual([scope.values[0]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should select from object', function() {
|
||||||
|
createSelect({
|
||||||
|
'ng:model':'selected',
|
||||||
|
'multiple':true,
|
||||||
|
'ng:options':'key as value for (key,value) in values'
|
||||||
|
});
|
||||||
|
scope.values = {'0':'A', '1':'B'};
|
||||||
|
|
||||||
|
scope.selected = ['1'];
|
||||||
|
scope.$digest();
|
||||||
|
expect(select.find('option')[1].selected).toBe(true);
|
||||||
|
|
||||||
|
select.find('option')[0].selected = true;
|
||||||
|
browserTrigger(select, 'change');
|
||||||
|
expect(scope.selected).toEqual(['0', '1']);
|
||||||
|
|
||||||
|
select.find('option')[1].selected = false;
|
||||||
|
browserTrigger(select, 'change');
|
||||||
|
expect(scope.selected).toEqual(['0']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue