Requirement: I have a fragment.xml
file which I am extending. The form element is currently being processed with a formatter.js
where I am validating some values based on some condition:
In Fragment, the formatter function is getting called correctly
<Text text="{
parts: [
{path: 'ZName1'},
{path: 'ZStatus1'}
],
formatter: '.Formatter.delivery'
}" >
Formatter:
delivery: function(iName, iStatus) {
var sResult = "";
if(iStatus === "A" ) {
sResult = iName ;
} else if(iStatus === "P") {
sResult = iName ;
} else {
sResult = iName ;
}
return sResult ;
}
In the output, I should get sResult
highlighted either in green, yellow, or red based on the condition.
In Fragment file:
In CSS file:
In Formatter file:
Binding on text will not work for highlighting the text. refer the example for alternative solution.
In Format.js file:
Instead of plain
sap.m.Text
, take advantage ofsap.m.ObjectStatus
which works exactly likeText
but supports semantic colors (viastate
) out-of-the-box.Run the following snippet to see the results:
We can see green, yellow, and red depending on the condition.