I am working on a SAPUI5 freestyle app where I have to implement a custom sap.ui.model.type.Unit. So what I did is the following:
In my onInit, I am binding the value-property of an sap.m.Input like this:
this.byId("input").bindValue({
parts: ["test>/arbeit/value", "test>/arbeit/unit"],
type: "sap.ui.model.type.Unit",
constraints: {
precision: "7",
scale: "1",
minimum: "0,25",
},
formatOptions: {
decimals: "1",
customUnits: {
H: {
displayName: "H",
"unitPattern-count-one": "{0} H",
"unitPattern-count-other": "{0} H",
decimals: "1",
},
},
},
});
This works like a charm, when reading data from a model like this JSON:
{
"selected": true,
"arbeit": {
"value": 10.0,
"unit": "H"
},
"currency": {
"value": 10.0,
"unit": "EUR"
}
}
But as soon as I enter a new value (e.g. 20) into the input field, I get an assertion error which says:
assert-dbg.js?eval:34 Assertion failed: Cannot find unit for input: '20'
So I debugged the Numberformat and the UnitType and I compared it to the sap.ui.model.type.Currency and somehow when I enter a new value in a currency-typed field, the currency is getting concatenated to the entered value like 20 -> 20 EUR and only after that, it gets parsed.
I want this exact behavior with my custom unit-type.
I only get no error when I enter a value with the unit together like 10 H. But I don't want to enter the unit each time I enter a new value.
I hope you guys understand what my problem is. Do you know what I am missing?