Show TOC

Step 4: Smart FormLocate this document in the navigation structure

The SmartForm control is used to obtain a form-like layout for several controls.

SmartForm internally uses the sap.ui.layout.form.Form control. When using the SmartForm control in combination with the SmartField controls, the view.xml file remains very compact since required information about labels and headers is automatically extracted from the OData metadata. In addition, you can specify in SmartForm that it is toggle-editable in which case you get the option to switch between read-only and edit mode. In this case, the powerful features of the SmartField control really come to life, such as the value help and the smart links.

Figure 1: Smart Form with Several Smart Fields (initial read-only mode)

When you press the pencil icon, the dialog for SmartForm becomes editable:

Figure 2: Smart Form with Several Smart Fields (edit mode)

When pressing the eyeglasses icon, you return to the display view of SmartForm.


You can view and download all files in the Explored app in the Demo Kit under Smart Controls - Step 4 - Smart Form.

				<smartForm:Group label="Product">
						<smartField:SmartField value="{ProductId}" />
						<smartField:SmartField value="{Name}" />
					<smartForm:GroupElement elementForLabel="1">
						<smartField:SmartField value="{CategoryName}" />
						<smartField:SmartField value="{Description}" />
						<smartField:SmartField value="{Price}" />
				<smartForm:Group label="Supplier">
						<smartField:SmartField value="{SupplierName}" />

We see that we have several new elements here. Group instructs the SmartForm to add a container for the child elements. In this case, we have two top-level containers of elements, one for Product and one for Supplier. With the GroupElement added as a wrapper control for SmartFields, we instruct the SmartForm to inspect the OData metadata and automatically add the labels found there. Within such GroupElements, we can even define a compound field having exactly one label in front. We do this in the example above in order to combine CategoryName with Description. With elementForLabel="1" we define that the label Description for SmartField (found in the OData metadata) is used for both fields. flexEnabled="false" is set to deactivate the flexibility services, since they are not part of this tutorial.

], function(Controller) {
	"use strict";

	return Controller.extend("sap.ui.demo.smartControls.SmartForm", {
		onInit: function() {


The controller follows the pattern that we already know.

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0"
	<edmx:DataServices m:DataServiceVersion="2.0">
		<Schema Namespace="" 
			sap:schema-version="1" xmlns="">
			<EntityType Name="Product">
					<PropertyRef Name="ProductId" />
				<Property Name="ProductId" Type="Edm.String" Nullable="false"
					sap:updatable="false" MaxLength="20" sap:label="Product ID" />
				<Property Name="Name" Type="Edm.String" Nullable="false"
					MaxLength="30" sap:label="Name" />
				<Property Name="CategoryName" Type="Edm.String" sap:label="Category Description"
					sap:updatable="true" />
				<Property Name="Description" Type="Edm.String" MaxLength="256"
					sap:label="Description" sap:updatable="true" />
				<Property Name="Price" Type="Edm.String" Nullable="false"
					sap:unit="CurrencyCode" MaxLength="3" sap:label="Price"
					sap:updatable="true" />
				<Property Name="CurrencyCode" Type="Edm.String" Nullable="true"
					MaxLength="3" sap:label="Currency" sap:semantics="currency-code"
					sap:updatable="true" />
				<Property Name="SupplierName" Type="Edm.String" Nullable="false"
					sap:label="Supplier" sap:updatable="true" />
			<EntityContainer m:IsDefaultEntityContainer="true"
				sap:supported-formats="atom json">
				<EntitySet Name="Products" EntityType="" />

With Nullable="false" we define that the field is mandatory and therefore cannot be null. The label for the mandatory field is then marked with * on the UI. Other than that, there are no substantial differences in the metadata file. We only notice that the sap:label attributes defined here appear in the final form as explained before.

	"ProductId": "4711",
	"Name": "Power Projector 4711",
	"CategoryName": "Projector",
	"SupplierName": "Titanium",
	"Description": "A very powerful projector with special features for Internet usability, USB",
	"Price": 856.49,
	"CurrencyCode": "EUR"

We see that a few attributes have been changed and added to the JSON file, reflecting the fact that, in this step, more data is shown.