Show TOC

Example: Using Data TypesLocate this document in the navigation structure

Example, how data types are used in the data binding type system.

A sap.ui.model.type.Float type is created with the formatting options minimum/maximum fraction digits equals 2 and a maximum value constraint of 10:

// creating of a float type with 2 format options and one constraint
var oFloat = new sap.ui.model.type.Float(
  {
     minFractionDigits: 2,
     maxFractionDigits: 2    		
  },
  {
     maximum: 10
  }
);

To use the defined data type for the binding, proceed as follows:

// specify the binding and the type directly in the control constructor
var oText = new sap.ui.commons.TextField({value: {path: "/sliderValue", type: oFloat}});
// or alternatively do it afterwards
oText.bindValue("/sliderValue", oFloat);

Input parsing and output formatting are now carried out automatically. If, for example, the float value in the model is 2.3345, the text field displays the value 2.33. A user enters a value which is validated after user entry. To be valid, the entered value must be lower than 10.