Skip to content

Commit b3f386f

Browse files
author
Nedyalko Nikolov
committed
Merge pull request NativeScript#150 from NativeScript/nnikolov/BindingWithSourceIssue
Fixed issue when UI element is bound to source different from binding…
2 parents ed98e53 + bb57bfb commit b3f386f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

apps/tests/ui/bindable-tests.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,26 @@ export var test_BindingContext_NavigatingForwardAndBack = function () {
490490
}
491491

492492
helper.navigateToModuleAndRunTest("./tests/ui/bindingContext_testPage1", null, testFunc);
493+
}
494+
495+
export var test_BindingToSource_FailsAfterBindingContextChange = function () {
496+
var createLabel = function () {
497+
var label = new labelModule.Label();
498+
return label;
499+
}
500+
var labelViewModel = new observable.Observable();
501+
var expectedValue = "testValue";
502+
labelViewModel.set("testProperty", expectedValue);
503+
504+
var testFunc = function (views: Array<viewModule.View>) {
505+
var testLabel = <labelModule.Label>(views[0]);
506+
testLabel.bind({ sourceProperty: "testProperty", targetProperty: "text" }, labelViewModel);
507+
508+
var page = <pageModule.Page>(views[1]);
509+
page.bindingContext = new observable.Observable;
510+
511+
TKUnit.assertEqual(testLabel.text, expectedValue);
512+
}
513+
514+
helper.buildUIAndRunTest(createLabel(), testFunc);
493515
}

ui/core/bindable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ export class Bindable extends dependencyObservable.DependencyObservable implemen
102102
for (var p in this._bindings) {
103103
binding = this._bindings[p];
104104

105-
if (binding.updating) {
105+
var sourceIsNotBindingContext = (binding.source && (binding.source.get() !== oldValue));
106+
if (binding.updating || sourceIsNotBindingContext) {
106107
continue;
107108
}
108109

0 commit comments

Comments
 (0)