class sap.ui.model.odata.type.Unit

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/odata/type/Unit
Application Component: CA-UI5-COR

This class represents the Unit composite type with the parts measure, unit, and unit customizing. The type may only be used for measure and unit parts from a sap.ui.model.odata.v4.ODataModel or a sap.ui.model.odata.v2.ODataModel. The measure part is formatted according to the customizing for the unit. Use the result of the promise returned by sap.ui.model.odata.v4.ODataMetaModel#requestUnitsOfMeasure for OData V4 or by sap.ui.model.odata.ODataMetaModel#requestUnitsOfMeasure for OData V2 as unit customizing part. If no unit customizing is available, UI5's default formatting applies.


Constructor

Constructor for a Unit composite type.

new sap.ui.model.odata.type.Unit(oFormatOptions?, oConstraints?, aDynamicFormatOptionNames?)
Param Type Default Value Description
oFormatOptions? object

See parameter oFormatOptions of sap.ui.model.type.Unit#constructor. Format options are immutable, that is, they can only be set once on construction. Format options that are not supported or have a different default are listed below. If the format option showMeasure is set to false, model messages for the unit of measure are not propagated to the control if the corresponding binding supports the feature of ignoring messages, see sap.ui.model.Binding#supportsIgnoreMessages, and the corresponding binding parameter is not set manually.

customUnits? object

Not supported; the type derives this from its unit customizing part.

parseAsString? boolean true

Whether the measure is parsed to a string; set to false if the measure's underlying type is represented as a number, for example sap.ui.model.odata.type.Int32

preserveDecimals? boolean true

By default decimals are preserved, unless oFormatOptions.style is given as "short" or "long"; since 1.89.0

unitOptional? boolean

Whether the measure is parsed if no unit is entered; defaults to true if neither showMeasure nor showNumber is set to a falsy value, otherwise defaults to false

emptyString? any 0

Defines how an empty string is parsed into the measure. With the default value 0 the measure becomes 0 when an empty string is parsed.

oConstraints? object

Only the 'skipDecimalsValidation' constraint is supported. Constraints are immutable, that is, they can only be set once on construction.

skipDecimalsValidation? boolean false

Whether to skip validation of the number of decimals based on the code list customizing; since 1.93.0

aDynamicFormatOptionNames? string[]

Not supported


Methods Overview

Method Description
sap.ui.model.odata.type.Unit.extend

Creates a new subclass of class sap.ui.model.odata.type.Unit with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.type.Unit.extend.

formatValue

Formats the given values of the parts of the Unit composite type to the given target type.

sap.ui.model.odata.type.Unit.getMetadata

Returns a metadata object for class sap.ui.model.odata.type.Unit.

getName

Returns the type's name.

parseValue

Parses the given string value to an array containing measure and unit.

References:

  • sap.ui.model.type.Unit#parseValue

validateValue

Validates whether the given value in model representation as returned by #parseValue is valid and meets the conditions of this type's unit customizing.

sap.ui.model.odata.type.Unit.extend

Creates a new subclass of class sap.ui.model.odata.type.Unit with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.type.Unit.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

formatValue

Formats the given values of the parts of the Unit composite type to the given target type.

Param Type DefaultValue Description
aValues any[]

Array of part values to be formatted; contains in the following order: measure, unit, unit customizing. The first call to this method where all parts are set determines the unit customizing; subsequent calls use this customizing, so that the corresponding part may be omitted. Changes to the unit customizing part after this first method call are not considered: The unit customizing for this Unit instance remains unchanged.

sTargetType string

The target type; must be "string" or a type with "string" as its primitive type. See sap.ui.model.odata.type for more information.

sap.ui.model.odata.type.Unit.getMetadata

Returns a metadata object for class sap.ui.model.odata.type.Unit.

getName

Returns the type's name.

parseValue

Parses the given string value to an array containing measure and unit.

References:

Param Type DefaultValue Description
vValue string

The value to be parsed

sSourceType string

The source type (the expected type of vValue); must be "string", or a type with "string" as its primitive type. See sap.ui.model.odata.type for more information.

aCurrentValues any[]

Not used

validateValue

Validates whether the given value in model representation as returned by #parseValue is valid and meets the conditions of this type's unit customizing.

Param Type DefaultValue Description
aValues any[]

An array containing measure and unit in this order, see return value of #parseValue