1

I have a list of elements (OData set) and use a binding to show this list. One field is for a quantity value and this value could sometimes need some decimal places.

The requirement is: only show that amount of decimal numbers that is also available in the OData service.

Annotation techniques can't be used.

I 'hacked' something that is misusing a formatter to update the type of a binding. But this is 'a hack' and it is not possible to convert it to XML views. (The reason is a different handling of the scope the formatter will be called).

So I am searching for a working solution for XML views.

The following code would not work but shows the issue:

new sap.m.Input({ // looking for an XML solution with bindings
  value: {
      path: "Quantity",
      type: new sap.ui.model.type.Float({
          // formatOptions
          maxFractionDigits: "{QuantityDecimals}",
          // ...
      }, {
          // constraints
          minimum: 0
      }),
      // ...
  }   
});

The maxFractionDigits : "{QuantityDecimals}" should be "dynamic" and not a constant value.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
user3783327
  • 616
  • 8
  • 30
  • 60
  • Why not you create a formatter in XML? – Piyush aggarwal Jan 10 '19 at 05:34
  • I have not tested it but, I think, the same sytax with type:... can be used in XML as well. May be you can check this article: https://archive.sap.com/discussions/thread/3624765 – Piyush aggarwal Jan 10 '19 at 05:39
  • The comments do not answer my question. The question is the "dynamic" handling of number of allowed floats. Assume you have a quantity field in a list. Sometimes you allow decimals (for KG or so) but most of the time it is not allowed because it must be a nattural number. The hack works because of JavaScript allows this. With XML view it is not possible this way. – user3783327 May 02 '22 at 12:01
  • @user3783327 Could you create an issue on GitHub? As described in my answer below.. – Boghyon Hoffmann Jan 19 '23 at 11:03

2 Answers2

2

Setting formatOptions and constraints dynamically in XML (via bindings or a declared function) is unfortunately not (yet) supported. But IMHO this is a valid enhancement request that app developers would greatly benefit from, since it encourages declarative programming.

I already asked for the same feature some years ago but in a comment at https://github.com/SAP/openui5/issues/2449#issuecomment-474304965 (See my answer to Frank's question "If XMLViews would allow a way to specify the dynamic constraints as well (e.g. enhanced syntax), would that fix the problem?").

Please create a new issue via https://github.com/SAP/openui5/issues/new with a clear description of what kind of problems the feature would resolve and possibly other use cases (You can add a link to my comment). I'll add my to your GitHub issue, and hopefully others too.


I'll update this answer as soon as the feature is available.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
0

Get your dynamic number from your model and store it in a JS variable.

var nQuantityDecimals = this.getModel().getProperty("/QuantityDecimals");

new sap.m.Input({
    value : {
        path : "Quantity",
        type : new sap.ui.model.type.Float({
            maxFractionDigits : nQuantityDecimals,
            source : {
                groupingSeparator: ",",
                decimalSeparator: ".",
                groupingEnabled: false
            }
        }, {
            minimum:0
        })
    }   
}),
alexP
  • 3,672
  • 7
  • 27
  • 36
  • More or less my existing hack works like this, my problem is to have a JS view. And I would also be happy to avoid some strange ID handling to get a control in the controller. – user3783327 Jan 11 '19 at 11:32