Themasterhimself
Themasterhimself

Reputation: 1016

SAPUI5 - formatter function not working

  var addressTxt = new sap.ui.commons.Label({
                id : 'addressTxt',
                text : {
                    parts : [
                             {path : 'Street'},
                             {path : 'PostalCode'},
                             ],
                    formatter : function(Street,PostalCode){
                        var text = "";
                        if(Street)  text = Street+ ",";
                        if(PostalCode) text += PostalCode +","

                        return text;
                    }        
                }
                        });

I am using the the formatter function to concatenate two elements in to a text field here, how ever the values for the parameters are always null. What am I doing wrong?

Upvotes: 4

Views: 20036

Answers (1)

cschuff
cschuff

Reputation: 5542

Here you go: http://jsbin.com/openui5-HTML-templates/82/edit?html,output

Think your main mistake was the parts array that is build without additional objects and 'path'. It directly takes the paths. Furthermore as long as the path is absolute inside of your model it needs to start with '/':

text : { 
    parts : [ '/street', '/postalCode' ],
    formatter : function(street, postalCode) {
        var text = "";
        if (street) text = street +",";
        if (postalCode) text += postalCode;
        return text;
    }
}

Find some more details on calculated fields in the docs here: https://openui5.hana.ondemand.com/#docs/guide/CalcFields.html

Upvotes: 4

Related Questions