0

How to call a formatter function with a static value from XML view?

I already tried:

<Input enabled="false" value="{'TestString', formatter:'.passStaticValue'}" />

There is no (syntax) error but the formatter will not call.

If I use the path-property everything works well.

I want to use this formatter function several times at several places:

  • One part with a value from the model
  • The other part as a static value.

The static value is to control the logic inside the formatter.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
SBIC
  • 35
  • 1
  • 8

3 Answers3

3

Just use

<Input enabled="false" value="{ path:'i18n>TestString', formatter:'.formatter.passStaticValue'}" />

You don't even need to define it on the i18n (resource model gives back the key if not defined)

-2

Can you try this code?

<Input 
    enabled="false"
    value="{ path:'TestString', formatter:'.formatter.passStaticValue'}" />
  • 1
    you need to be sure about your answers. Good luck in community. – cagdas Sep 25 '18 at 12:48
  • 1
    like that it just searches for the path 'TestString' and obv turn out empty since this path does not exist, you cannot pass the string like that, plainly wrong answer – Erch Sep 26 '18 at 06:11
  • Can you explain what EXTRA help ".formatter" will do? – Code_Tech Mar 07 '19 at 14:32
-3

You want to pass a simple value, which is not related in any way to the model, into your function?

<Input 
enabled="false"
value="{= passStaticValue('blubb')}" />

If I remember correctly, it is executed on level of the controller, so passStaticValue is expected to be a controller function

iPirat
  • 2,197
  • 1
  • 17
  • 30
  • like that you could just put the formatter functionallity in the controler method, or call it maually – Erch Sep 26 '18 at 08:50
  • @Erch ?? He has an existing formatter and wants to call it with a static value. What problem do you see here? – iPirat Sep 26 '18 at 14:01
  • none, just that the function, in your examle "passStaticValue" would not be found in model/formatter.js, it would be located in the controller of the xml view, if he already hast an working function in the formatter.js he either need to call that in said function or dublicate the code into that function – Erch Sep 27 '18 at 12:42
  • He is using `formatter:'.passStaticValue'` which is also located in controller! – iPirat Sep 27 '18 at 17:14
  • Good attempt, but can't unfortunately work since expression binding awaits one of the [supported a global symbols](https://github.com/SAP/openui5/blob/a5c80d622bb15c7525ac18bfb356073a1645c113/src/sap.ui.core/src/sap/ui/base/ExpressionParser.js#L28-L66) when calling a function like this. Would be a good enhancement request though – Boghyon Hoffmann Mar 07 '19 at 12:53