diff --git a/apps/tests/ui/bindable-tests.ts b/apps/tests/ui/bindable-tests.ts index 95075db06..ceaf16135 100644 --- a/apps/tests/ui/bindable-tests.ts +++ b/apps/tests/ui/bindable-tests.ts @@ -938,3 +938,28 @@ export var test_BindingHitsGetterTooManyTimes = function () { TKUnit.assertEqual(counter, 1, "Property getter should be hit only once!"); } + +export function test_SupportFunctionsInExpressions() { + var model = new observable.Observable({ + "anyColor": "red", + "isVisible": function () { + return this.get("anyColor") === "red"; + } + }); + + var bindableObj = new bindable.Bindable(); + + bindableObj.bind({ + "sourceProperty": "$value", + "targetProperty": "test", + "expression": "isVisible() ? 'visible' : 'collapsed'" + }, model); + + model.set("anyColor", "blue"); + + TKUnit.assertEqual(bindableObj.get("test"), "collapsed", "When anyColor is blue test property should be collapsed."); + + model.set("anyColor", "red"); + + TKUnit.assertEqual(bindableObj.get("test"), "visible", "When anyColor is red test property should be visible."); +} diff --git a/ui/core/bindable.ts b/ui/core/bindable.ts index 0a27ff69f..5cca53ba8 100644 --- a/ui/core/bindable.ts +++ b/ui/core/bindable.ts @@ -379,7 +379,7 @@ export class Binding { this.prepareContextForExpression(context, expression); model[contextKey] = context; - return exp.getValue(model, isBackConvert, changedModel); + return exp.getValue(model, isBackConvert, changedModel ? changedModel : model); } return new Error(expression + " is not a valid expression."); }