Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3353

How to reference control element in formatter after switch to sap.ui.define

$
0
0

Hi everyone,

 

we move our codebase from the require/declare syntax to the AMD sap.ui.define pattern.

 

We encounter a couple of problems of course. We define a couple of non basic formatter functions. Here a couple of code examples:

 

Controller head, you can see that we reference the formatter here with:

formatter: Formatter,
sap.ui.define([   "sap/ui/core/mvc/Controller",   "our/code/base/util/Navigation",   "our/code/base/util/Lock",   "our/code/base/util/Grouper",   "our/code/base/util/Formatter"
], function (Controller, Navigation, Lock, Grouper, Formatter) {   "use strict";   return Controller.extend("our.code.base.view.Master", {   formatter: Formatter,

As you can see here in the XML view, that we use the formatter with

.formatter.date
          <attributes>            <ObjectAttribute text="Workflow: {Workflowtyp}" />            <ObjectAttribute title="{i18n>TransmissionDate}" text="{              path: 'Sendedatum',              formatter: '.formatter.date'              }" />

 

Here the formatter definition

sap.ui.define([  "sap/ui/core/format/NumberFormat",  "sap/ui/core/format/DateFormat",  "our/code/base/util/Basic",  "sap/ui/core/ValueState"
], function (NumberFormat, DateFormat, Basic, ValueState) {  "use strict";  return {   levelState:  function (currentLevel, maxLevel) {     var map = this.formatter._statusStateMap;     if (currentLevel === maxLevel) {       currentlevel = "3";     } else if(currentLevel > 1) {       currentLevel = "2";     }     return (currentLevel && map[currentLevel]) ? map[currentLevel] : ValueState.None;   },   cashDiscountState:  function (date) {     if ( ! this.formatter._isDateValid(date)) {       console.log(this.getMetadata());       this.setVisible(false);       return;     }

As you can see, we reference our formatter again here, with

this.formatter._isDateValid(date)

In the old code base, we were able to use our.code.base.Formatter._isDateValid, but the new scope does not allow that. We have these helper functions to share them between formatters.

 

Because the formatter is apparently designed as being a part of the view itself, we are able to reference the formatter with this.formatter, because this is referencing the Master view.

 

But, and here is the big problem we have, we are not able to access the element that gets currently formatted anymore!

 

But that's how it worked before we went the road of the new module definitions. Ok, so do you have any ideas, how to access the element which gets formatted at the moment?


Viewing all articles
Browse latest Browse all 3353

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>