SAPUI5 - formatter function not working

19,205

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

Share:
19,205
Themasterhimself
Author by

Themasterhimself

Updated on June 12, 2022

Comments

  • Themasterhimself
    Themasterhimself almost 2 years
      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?