Cause
In a property binding, using ...
... turns the binding mode into OneWay. Unless only the path
is defined in the binding info object (not parts
), all the above cases make use of the module sap.ui.model.CompositeBinding
.
Resolution
Expression Binding definition as it's written in the question cannot become TwoWay.
However, CompositeBinding
does allow TwoWay binding by having a type
to the property binding info assigned that is derived from sap.ui.model.CompositeType
.
- Use either one of the existing data type classes derived from the
CompositeType
(Click on "View subclasses" in the API reference)
- Or define your own composite type class.
Sample Currency
type definition from UI5.
Sample ternary type that behaves like the above Expression Binding definition: https://embed.plnkr.co/0MVvfZ/?show=view%2FHome.view.xml,preview
It takes all three parts
necessary for the ternary operation; one for the condition, one for binding the truthy case (a
), and one for binding the falsy case (b
):
<Input value="{
parts: [
'/myTruthyOrFalsyValue',
'a>/bindingThisTwoWayIfTruthy',
'b>/bindingThisTwoWayIfFalsy'
],
type: 'demo.model.type.MyTernary'
}" />
The actual ternary operation happens in the type definition which could look something like this:
sap.ui.define([
"sap/ui/model/CompositeType"
], function(CompositeType) {
"use strict";
return CompositeType.extend("demo.model.type.MyTernary", {
constructor: function() {
CompositeType.apply(this, arguments);
this.bParseWithValues = true; // Publicly documented. Make 'parts' available in parseValue
},
/**
* Displaying data from the right model (model -> view)
*/
formatValue: parts => parts[0] ? parts[1] : parts[2],
/**
* Assigning entered value to the right model (view -> model)
*/
parseValue: (enteredValue, stuff, parts) => parts[0] ? [
parts[0],
enteredValue,
parts[2],
] : [
parts[0],
parts[1],
enteredValue,
],
validateValue: () => true // Nothing to validate here
});
});
Prerequisites
In order to allow TwoWay composite binding, all binding parts
must have the TwoWay binding mode enabled:
Note that a composite binding will be forced into mode OneWay when one of the binding parts
is not in mode TwoWay. (Source: ManagedObject#bindProperty
)
Ensure that the bootstrap configuration option sap-ui-compatVersion
is set to "edge"
.