2

I am trying to call a the formatter. e.g. to transform a text to uppercase. I have two formatters, one is in the controller and one is globally in the utils folder.

i tried to call both, but none is called. Can someone help me please :(?

I have a global formatter in utils folder:

jQuery.sap.declare("my.app.util.Formatter");
my.app.util.Formatter = {

    toUpperCase: function(sStr) {
        return sStr.toUpperCase();
    }

};

and one formatter in my controller (i do the require $.sap.require("my.app.util.Formatter"); as well):

myControllerToUpperCaseFormatter : function(sStr) {
  console.log('I WILL DO NOTHING!');
  return sStr.toUpperCase();
}

my XML:

<mvc:View controllerName="my.app.view.XXX"
xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:l="sap.ui.layout"
xmlns:f="sap.ui.layout.form" xmlns:c="sap.ui.core" xmlns="sap.m">
<Page class="sapUiFioriObjectPage" title="Test">
    <content>

        <Button text="{path: 'MyModel>/name', formatter: 'my.app.util.Formatter.toUpperCase'}"></Button>

        <Button text="{path: 'MyModel>/name', formatter: '.myControllerToUpperCaseFormatter' }"></Button>

    </content>
</Page>

Thanks for the help!

ale
  • 23
  • 1
  • 2
  • 4
  • Have you specified, in the UI5 bootstrap, that you want support for "complex" binding syntax? `data-sap-ui-xx-bindingSyntax="complex"` – qmacro May 09 '15 at 12:22

2 Answers2

1

Your binding doesn't look correct

MyModel>/name // it states that name is a property at the root of the data property hierarchy. Right Way:

<Button text="{path: 'MyModel>name', formatter: '.myControllerToUpperCaseFormatter' }"></Button>

Nevertheless, I too sometimes have faced this issue!

For some reason, when two or more parameters are used it started working.

Example:

<Button text="{parts:[{path:'MyModel>name'},{path:'MyModel>somethingElse'}],formatter: '.myControllerToUpperCaseFormatter' }"></Button>

Other Solution:

Looks like you are binding the data from UI controller. If yes, format the data you want and then set it to model.

Sunil B N
  • 4,159
  • 1
  • 31
  • 52
0

data-sap-ui-xx-bindingSyntax="complex" in the index.html is the reason why your complex bindings like formatter gets called.

barbsan
  • 3,418
  • 11
  • 21
  • 28
Arun
  • 21
  • 2
  • 1
    `xx-bindingsyntax` is experimental. Better use `compatversion="edge"` which sets the binding syntax automatically to `"complex"`. See https://stackoverflow.com/a/41554735/5846045 – Boghyon Hoffmann Jul 02 '19 at 09:58