From fc3c52691e99d58b55445fc3dbfe7b1ea083d3d7 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Mon, 31 Aug 2015 15:49:42 +0300 Subject: [PATCH] Fixed issue with binding when there is no sourceProperty set. --- apps/tests/ui/bindable-tests.ts | 18 ++++++++++++++++++ ui/core/bindable.ts | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index fa74af4f9..f8f394598 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -887,4 +887,22 @@ export function test_NestedPropertiesBindingTwoTargetsAndReplacingSomeNestedObje (act1).Owner = newPerson; TKUnit.assertEqual(target2.get("targetProp"), secondExpectedFirstName); +} + +export function test_NullSourcePropertyShouldNotCrash() { + var expectedValue = "Expected Value"; + var target = new bindable.Bindable(); + var convFunc = function (value) { + return value + "Converted"; + } + var model = new observable.Observable(); + model.set("field", expectedValue); + model.set("convFunc", convFunc); + target.bind({ + sourceProperty: null, + targetProperty: "targetProp", + expression: "convFunc(field)" + }, model); + + TKUnit.assertEqual(target.get("targetProp"), convFunc(expectedValue)); } \ No newline at end of file diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 1f1fbf4d5..b79e922e3 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -187,8 +187,13 @@ export class Binding { return this.sourcePropertiesArray; } - private static getProperties(property: string) { - return property.split("."); + private static getProperties(property: string): Array { + if (property) { + return property.split("."); + } + else { + return []; + } } private resolveObjectsAndProperties(source: Object, propsArray: Array) {