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

Commit fcde331

Browse files
committed
WIP: fix updating viewValue from element's val
1 parent ef0dc2c commit fcde331

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/ng/directive/select.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,14 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
402402
if ((optionElement = optionGroup[index].element)[0].selected) {
403403
key = optionElement.val();
404404
if (keyName) locals[keyName] = key;
405-
if (trackFn) {
405+
if (selectAsFn) {
406+
var collectionWithValueName = {};
407+
collectionWithValueName[valueName] = collection[key];
408+
for (i = 0; i < collection.length; i++) {
409+
locals[valueName] = collection[i];
410+
if (selectAsFn(scope, locals) == selectAsFn(scope, collectionWithValueName)) break;
411+
}
412+
} else if (trackFn) {
406413
for (trackIndex = 0; trackIndex < collection.length; trackIndex++) {
407414
locals[valueName] = collection[trackIndex];
408415
if (trackFn(scope, locals) == key) break;
@@ -421,9 +428,21 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
421428
} else if (key === ''){
422429
value = null;
423430
} else {
424-
if (trackFn) {
431+
if (selectAsFn) {
432+
for (i = 0; i < collection.length; i++) {
433+
locals[valueName] = collection[i];
434+
var collectionWithValueName = {};
435+
collectionWithValueName[valueName] = collection[key];
436+
437+
if (selectAsFn(scope, locals) === selectAsFn(scope, collectionWithValueName)) {
438+
value = selectAsFn(scope, locals);
439+
break;
440+
}
441+
}
442+
} else if (trackFn) {
425443
for (trackIndex = 0; trackIndex < collection.length; trackIndex++) {
426444
locals[valueName] = collection[trackIndex];
445+
427446
if (trackFn(scope, locals) == key) {
428447
value = valueFn(scope, locals);
429448
break;

test/ng/directive/selectSpec.js

-2
Original file line numberDiff line numberDiff line change
@@ -1511,11 +1511,9 @@ describe('select', function() {
15111511

15121512
expect(element.val()).toEqual(['1']);
15131513

1514-
dump('triggering!');
15151514
element.val(['0']);
15161515
browserTrigger(element, 'change');
15171516
scope.$digest();
1518-
dump(element);
15191517

15201518
expect(scope.selected).toEqual([10]);
15211519
});

0 commit comments

Comments
 (0)