I've started with my first SAPUI5 application and I wanna use the Tool Header item like in the Demo Kit.
(I'm using an XML-View.)
I've included it into my view but now I get the error:
UIComponent.js:6 Uncaught Error: failed to load 'sap/tnt/ToolHeader.js' from resources/sap/tnt/ToolHeader.js: 404 - Not Found
Do I have embed a special script in my application? (Which one?)
page.view.xml
<mvc:View
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
xmlns:tnt="sap.tnt"
xmlns:html="http://www.w3.org/1999/xhtml"
controllerName="zdemo.controller.MachDetail">
<tnt:ToolHeader>
<Button icon="sap-icon://menu2" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" />
</layoutData>
</Button>
<ToolbarSpacer width="20px" />
<Button text="File" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Edit" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="View" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Navigate" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Code" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Refactor" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Run" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<Button text="Tools" type="Transparent">
<layoutData>
<OverflowToolbarLayoutData priority="Low" />
</layoutData>
</Button>
<tnt:ToolHeaderUtilitySeparator />
<ToolbarSpacer>
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" minWidth="20px" />
</layoutData>
</ToolbarSpacer>
<Button text="Alan Smith" type="Transparent" press="handleUserNamePress">
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" />
</layoutData>
</Button>
</tnt:ToolHeader>
</mvc:View>
the only one script in my index.html
<script src="resources/sap-ui-core.js"
data-sap-ui-xx-bindingSyntax="complex" id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m" data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-resourceroots='{ "zdemo":"./"
}'>
Your code is correct, but according to the comments, you are using an older version which does not yet include the ToolHeader control.
By upgrading to SAPUI5 1.34+ you will be able to use the ToolHeader with the same code.
The documentation for the control includes the information when the control was added.
You need import module dependency "sap.tnt" to your project. You can do it this way:
1. install dependency via bower
bower install openui5/packaged-sap.tnt
if you need another dependency, you can find here: https://github.com/openui5
2. add reference lib to index.html
<script .... data-sap-ui-libs="sap.m, sap.tnt"></script>
3. if you use grunt serve, expose dependency resources by openui5_connect
on file Gruntfile.js, find openui5_connect key and add
openui5_connect: {
options: {
resources: [
...
'bower_components/openui5-sap.tnt/resources',
],
testresources: [
...
'bower_components/openui5-sap.tnt/test-resources'
]
}
}
4. To finish, add dependency entry to manifest.json
"sap.ui5": {
"dependencies": {
"libs": {
...
"sap.tnt": {}
}
}
}
And run your app
Related
I have designed a simple form as defined. If I want to add a message down to the checkboxes, how can we add the message? I am expecting output as like this:
<Label text="..." required="true">
<layoutData>
<l:GridData span="L2 M3 S7"/>
</layoutData>
</Label>
<Select>
<layoutData>
<l:GridData span="L2 M3 S5"/>
</layoutData>
</Select>
<CheckBox text="....">
<layoutData>
<l:GridData span="L2 M3 S7"/>
</layoutData>
</CheckBox>
<TextArea value=" " rows="3">
<layoutData>
<l:GridData span="L2 M3 S5"/>
</layoutData>
</TextArea>
<CheckBox text="...." >
<layoutData>
<l:GridData span="L2 M3 S7"/>
</layoutData>
</CheckBox>
<TextArea value=" " rows="3">
<layoutData>
<l:GridData span="L2 M3 S5"/>
</layoutData>
</TextArea>
You can achieve it by using VBox control
<CheckBox text="Custom Note">
<layoutData>
<l:GridData span="L2 M3 S6"/>
</layoutData>
</CheckBox>
<VBox>
<TextArea value=" " rows="3" />
<Label text="Max allowed chars 150" wrapping="true"/>
<layoutData>
<l:GridData span="L2 M3 S6"/>
</layoutData>
</VBox>
<CheckBox text="Exception" >
<layoutData>
<l:GridData span="L2 M3 S6"/>
</layoutData>
</CheckBox>
<VBox>
<TextArea value=" " rows="3"/>
<Label text="Max allowed chars 150" wrapping="true"/>
<layoutData>
<l:GridData span="L2 M3 S6"/>
</layoutData>
</VBox>
Output
I am expecting output as like this:
For the CheckBox, use the property text.
For the character limit message below the TextArea, there are two options:
Without value-binding: simply define maxLength and set showExceededText="true".
With value-binding: bind value with the type sap.ui.model(.odata).type.String and maxLength: 150. UI5 will handle displaying message accordingly if the character limit is exceeded. See the documentation topic Error, Warning, and Info Messages for more information.
sap.ui.getCore().attachInit(() => sap.ui.require([
"sap/ui/core/Fragment",
"sap/ui/model/json/JSONModel",
"sap/ui/core/Core",
], (Fragment, JSONModel, Core) => Fragment.load({
definition: `<App xmlns="sap.m" autoFocus="false">
<Page class="sapUiResponsiveContentPadding" showHeader="false">
<HBox renderType="Bare" justifyContent="SpaceAround">
<CheckBox text="My custom checkbox text" />
<TextArea xmlns:core="sap.ui.core" core:require="{ StringType: 'sap/ui/model/type/String' }"
value="{
path: '/value',
type: 'StringType',
constraints: {
maxLength: 150
}
}"
maxLength="150"
width="100%"
height="5.5rem"
showExceededText="true"
>
<layoutData>
<FlexItemData maxWidth="13rem"/>
</layoutData>
</TextArea>
</HBox>
</Page>
</App>`,
}).then(control => Core.getMessageManager().registerObject(control.setModel(new JSONModel({
value: "",
})).placeAt("content"), true))));
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core, sap.m"
data-sap-ui-async="true"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-compatversion="edge"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>
If the limit is exceeded (with value-binding and type):
How I can put my icon next to or within the input field?
The problem is, the icon changes the form. Usually, it's like this:
But when I'm adding the icon (code below), it displaces the Dauer input Field.
Is there a way to make it look clean and that's next to it? Or better in the input field inside?
I can make the button smaller with CSS but there is still a gap between them.. And it does not move automatically.
The best solution is like the Datum above with a small icon inside where I can click or like the icon is next to the Dauer without no gap between input field from Dauer and the ? icon.
PS: I just want it like this (I will decide then later which option is better. But it is possible?)
<form:SimpleForm id="neuezeiterfassung"
editable="true"
title="Neue Zeiterfassung anlegen"
>
<Label
text="Auftrag"
class="font1"
tooltip="Auftrag eingeben"
/>
<l:VerticalLayout>
<ComboBox id="Auftrag"
items="{/ZAUFKSet}"
showSecondaryValues="true"
width="50%"
>
<core:ListItem text="{Aufnr}" />
</ComboBox>
</l:VerticalLayout>
<Label
text="Datum"
class="font1"
/>
<DatePicker id="DP3"
valueFormat="dd.MM.yyyy"
displayFormat="medium"
width="50%"
placeholder="dd.mm.yyyy"
/>
<Label class="font1" text="Dauer" />
<Input id="dauer"
class="dauer"
placeholder="Dauer eingeben ... "
width="50%"
/>
<HBox class="sapUiSmallMargin">
<core:Icon
src="sap-icon://sys-help"
class="size1" color="#031E48" press="aseads"
>
<core:layoutData>
<FlexItemData growFactor="1" />
</core:layoutData>
</core:Icon>
</HBox>
<!-- <Button icon="sap-icon://sys-help" class="myButton"/> -->
<Label class="font1" text="Arbeitsbeschreibung" />
<TextArea id="beschreibung" width="50%" />
</form:SimpleForm>
Update: with the change in commit:8f1757d, which is available since UI5 1.84, the value help icon can be changed via valueHelpIconSrc:
<Input showValueHelp="true"
valueHelpIconSrc="sap-icon://sys-help"
valueHelpRequest="alert('Help requested')"
/><!-- valueHelpIconSrc available since 1.84.0 -->
No need to extend sap.m.InputBase in this case. Other input controls like sap.m.MaskInput still need to be extended as shown in the linked Plunk below.
Original answer:
The best solution is like the Datum above with a small icon inside where I can click. (...) Is it possible?
Yes, it's possible. Here is a minimal example: https://embed.plnkr.co/EzlF2tkvalJWvSEn
For this, UI5 provides the API addEndIconapi which is protected, meaning it should be used only when extending sap.m.InputBase!
As an argument for the addEndIcon, you can pass a map of settings that are required to create sap.ui.core.Iconapi, which is highly customizable.
const icon = this.addEndIcon({
id: this.getId() + "-questionMarkBtn",
src: IconPool.getIconURI("sys-help"),
noTabStop: true,
tooltip: "Information",
press: [this.onEndButtonPress, this],
}); // See sap.ui.core.Icon/properties for more settings
// icon.addStyleClass(...); if even more customization required..
You can achieve it using the below code, just updated the CSS as per your requirement. It is a responsive design, it will work for all the devices.
CODE
<VBox class="sapUiSmallMargin">
<f:SimpleForm
editable="true"
layout="ResponsiveGridLayout"
title="Neue Zeiterfassung anlegen"
labelSpanXL="3"
labelSpanL="3"
labelSpanM="3"
labelSpanS="12"
adjustLabelSpan="false"
emptySpanXL="1"
emptySpanL="1"
emptySpanM="1"
emptySpanS="0"
columnsXL="1"
columnsL="1"
columnsM="1"
singleContainerFullSize="false" >
<f:content>
<Label text="Auftrag" tooltip="Auftrag eingeben" />
<ComboBox items="{/ZAUFKSet}" id="Auftrag" showSecondaryValues="true">
<core:ListItem text="{Aufnr}"/>
</ComboBox>
<Label text="Datum" labelFor="DP3"/>
<DatePicker id="DP3" valueFormat="dd.MM.yyyy" displayFormat="medium" placeholder="dd.mm.yyyy"/>
<Label class="font1" text="Dauer"/>
<Input value="Street">
<layoutData>
<l:GridData span="XL7 L7 M7 S10" />
</layoutData>
</Input>
<Button icon="sap-icon://sys-help" press="onPress" >
<layoutData>
<l:GridData span="XL1 L1 M1 S2" />
</layoutData>
</Button>
<Label text="Arbeitsbeschreibung"/>
<TextArea id="beschreibung"/>
</f:content>
</f:SimpleForm>
</VBox>
Output:
If you are looking for below output
<f:SimpleForm
editable="true"
layout="ResponsiveGridLayout"
title="Neue Zeiterfassung anlegen"
labelSpanXL="3"
labelSpanL="3"
labelSpanM="3"
labelSpanS="12"
adjustLabelSpan="false"
emptySpanXL="1"
emptySpanL="1"
emptySpanM="1"
emptySpanS="0"
columnsXL="1"
columnsL="1"
columnsM="1"
singleContainerFullSize="false" >
<f:content>
<Label text="Auftrag" tooltip="Auftrag eingeben" />
<ComboBox items="{/ZAUFKSet}" id="Auftrag" showSecondaryValues="true">
<core:ListItem text="{Aufnr}"/>
<layoutData>
<l:GridData span="XL8 L8 M7 S9" />
</layoutData>
</ComboBox>
<Label text="Datum" labelFor="DP3"/>
<DatePicker id="DP3" valueFormat="dd.MM.yyyy" displayFormat="medium"
placeholder="dd.mm.yyyy">
<layoutData>
<l:GridData span="XL8 L8 M7 S9" />
</layoutData>
</DatePicker>
<Label class="font1" text="Dauer"/>
<Input value="Street">
<layoutData>
<l:GridData span="XL8 L8 M7 S9" />
</layoutData>
</Input>
<Button icon="sap-icon://sys-help" press="onPress" width="40px" >
<layoutData>
<l:GridData span="XL1 L1 M1 S3" />
</layoutData>
</Button>
<Label text="Arbeitsbeschreibung"/>
<TextArea id="beschreibung">
<layoutData>
<l:GridData span="XL8 L8 M7 S9" />
</layoutData>
</TextArea>
</f:content>
</f:SimpleForm>
With icon
<VBox class="sapUiSmallMargin">
<f:SimpleForm
editable="true"
layout="ResponsiveGridLayout"
title="Neue Zeiterfassung anlegen"
labelSpanXL="3"
labelSpanL="3"
labelSpanM="3"
labelSpanS="12"
adjustLabelSpan="false"
emptySpanXL="1"
emptySpanL="1"
emptySpanM="1"
emptySpanS="0"
columnsXL="1"
columnsL="1"
columnsM="1"
singleContainerFullSize="false" >
<f:content>
<Label text="Auftrag" tooltip="Auftrag eingeben" />
<ComboBox items="{/ZAUFKSet}" id="Auftrag" showSecondaryValues="true">
<core:ListItem text="{Aufnr}"/>
<layoutData>
<l:GridData span="XL10 L10 M10 S10" />
</layoutData>
</ComboBox>
<Label text="Datum" labelFor="DP3"/>
<DatePicker id="DP3" valueFormat="dd.MM.yyyy" displayFormat="medium" placeholder="dd.mm.yyyy">
<layoutData>
<l:GridData span="XL10 L10 M10 S10" />
</layoutData>
</DatePicker>
<Label class="font1" text="Dauer"/>
<Input value="Street">
<layoutData>
<l:GridData span="XL10 L10 M10 S10" />
</layoutData>
</Input>
<HBox>
<core:Icon src="sap-icon://sys-help" color="#031E48" press="onPress" class="infoIcon"/>
<layoutData>
<l:GridData span="XL1 L1 M1 S1" />
</layoutData>
</HBox>
<Label text="Arbeitsbeschreibung"/>
<TextArea id="beschreibung">
<layoutData>
<l:GridData span="XL10 L10 M10 S10" />
</layoutData>
</TextArea>
</f:content>
</f:SimpleForm>
</VBox>
If you are using the ICON you need to add the style as well for alignment
.infoIcon {
line-height: 3rem;
}
Sometimes extending the InputBase class can be a bit overkill/increase the complexity of the code.
You can also use Flexbox containers to achieve the alignment of the input and the icon.
For example, if you want the input and the icon to be centered vertically and horizontally:
<HBox
alignItems="Center"
justifyContent="Center">
<Input>
<layoutData>
<FlexItemData growFactor="3" />
</layoutData>
</Input>
<core:Icon
src="sap-icon://sys-help">
<!-- Be careful here with the namespaces (use layoutData from core, not m) -->
<core:layoutData>
<FlexItemData growFactor="1" />
</core:layoutData>
</core:Icon>
</HBox>
This will give something like this:
See Flexbox for more examples (API Reference is available at the top of the page).
I defined the following simple form:
<form:SimpleForm id="SimpleFormChange354"
editable="true"
layout="ResponsiveGridLayout"
title="Address"
labelSpanXL="2"
labelSpanL="2"
labelSpanM="3"
labelSpanS="12"
adjustLabelSpan="false"
emptySpanXL="0"
emptySpanL="0"
emptySpanM="0"
emptySpanS="0"
columnsXL="2"
columnsL="2"
columnsM="1"
singleContainerFullSize="false"
>
<Label text="Name1"/>
<Input/>
<Label text="Name2"/>
<Input/>
<Label text="Name3"/>
<Input/>
</form:SimpleForm>
As you can see:
How to place the red marked element next to Name1 element?
In order to enable multiple columns, the property column* or the <layoutData> aggregation should be adjusted respectively in (Simple)Form.
Using ColumnLayout
As of v1.56, the new layout sap/ui/layout/form/ColumnLayout can be assigned to (Simple)Form which enables "a newspaper like style" without the need to insert any Titles, Toolbars, or any additional layout data to have multiple columns.
globalThis.onUI5Init = () => sap.ui.require([
"sap/ui/core/Fragment",
], async Fragment => {
"use strict";
const control = await Fragment.load({
definition: `<form:SimpleForm xmlns:form="sap.ui.layout.form" xmlns="sap.m"
title="Multiple Columns via ColumnLayout"
editable="true"
layout="ColumnLayout"
columnsM="2">
<Label text="Label 1"/>
<Input/>
<Label text="Label 2"/>
<Input/>
<Label text="Label 3"/>
<Input/>
</form:SimpleForm>`,
});
control.placeAt("content");
});
<script defer id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core,sap.m,sap.ui.layout"
data-sap-ui-oninit="onUI5Init"
data-sap-ui-async="true"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-compatversion="edge"
data-sap-ui-excludejquerycompat="true"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>
In case more adjustments are required, the layout data sap/ui/layout/form/ColumnElementData can be assigned. E.g.:
<Label text="Label 3">
<layoutData>
<form:ColumnElementData cellsSmall="3"/><!-- default: 12 -->
</layoutData>
</Label>
Resources
API reference: sap/ui/layout/form/ColumnLayout
Test Page for ColumnLayout (source code can be found here)
Using ResponsiveGridLayout
Not ResponsiveLayout as that is deprecated as of UI5 v1.93. ResponsiveGridLayout is still supported.
globalThis.onUI5Init = () => sap.ui.require([
"sap/ui/core/Fragment",
], async Fragment => {
"use strict";
const controls = await Fragment.load({
definition: `<core:FragmentDefinition
xmlns:core="sap.ui.core"
xmlns:form="sap.ui.layout.form"
xmlns:layout="sap.ui.layout"
xmlns="sap.m">
<form:SimpleForm
title="Multiple Columns via GridData"
editable="true"
layout="ResponsiveGridLayout">
<Label text="Label 1">
<layoutData>
<layout:GridData span="L2 M2"/>
</layoutData>
</Label>
<Input>
<layoutData>
<layout:GridData span="L4 M4"/>
</layoutData>
</Input>
<Label text="Label 2">
<layoutData>
<layout:GridData span="L2 M2"/>
</layoutData>
</Label>
<Input>
<layoutData>
<layout:GridData span="L4 M4"/>
</layoutData>
</Input>
<Label text="Label 3">
<layoutData>
<layout:GridData span="L2 M2"/>
</layoutData>
</Label>
<Input>
<layoutData>
<layout:GridData span="L4 M4"/>
</layoutData>
</Input>
</form:SimpleForm>
<form:SimpleForm
title="Multiple Columns via Containers (columns* + sap.ui.core.Title)"
editable="true"
layout="ResponsiveGridLayout"
columnsM="2">
<core:Title text="Container 1"/>
<Label text="Label 1"/>
<Input/>
<core:Title text="Container 2"/>
<Label text="Label 2"/>
<Input/>
<Label text="Label 3"/>
<Input/>
</form:SimpleForm>
</core:FragmentDefinition>`,
});
controls.map(control => control.placeAt("content"));
});
<script defer id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core,sap.m,sap.ui.layout"
data-sap-ui-oninit="onUI5Init"
data-sap-ui-async="true"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-compatversion="edge"
data-sap-ui-excludejquerycompat="true"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>
Resources
API reference: sap/ui/layout/form/ResponsiveGridLayout
API reference: sap/ui/layout/GridData
I'm trying to add 2 Input controls to my Toolbar with Title. But in OverflowToolbar they go to overflow area and in Toolbar control are not moved to the right side by ToolbarSpacer. How do I make this work as expected?
<Table
id="sfcTable"
mode="MultiSelect"
items="{path: 'sfcTable>/Rowsets/Rowset/0/Row', sorter: { path: 'Shop Order'}}">
<headerToolbar>
<OverflowToolbar>
<Title
text="Table Header Here"
level="H1" />
<ToolbarSpacer />
<Input
id="operationDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
<layoutData>
<OverflowToolbarLayoutData
priority="NeverOverflow" />
</layoutData>
</Input>
<Input
id="actionDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
<layoutData>
<OverflowToolbarLayoutData
priority="NeverOverflow" />
</layoutData>
</Input>
</OverflowToolbar>
</headerToolbar>
...
</Table>
OverflowToolbar image
Note that only one Input is shown.
Toolbar code:
<Table
id="sfcTable"
mode="MultiSelect"
items="{path: 'sfcTable>/Rowsets/Rowset/0/Row', sorter: { path: 'Shop Order'}}">
<headerToolbar>
<Toolbar>
<Title
text="Table Header Here"
level="H1" />
<ToolbarSpacer />
<Input
id="operationDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
</Input>
<Input
id="actionDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
</Input>
</Toolbar>
</headerToolbar>
Toolbar image
I also had the same problem at some point and ended up with wrapping the additional controls into a nested Toolbar. See working example in snippet below or at JSBin: http://jsbin.com/hofuvum/edit?html,output
<!DOCTYPE html>
<html><head>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<title>JSFragment used in XmlView</title>
<!-- Load UI5, select Blue Crystal theme and the "commons" control library -->
<script id='sap-ui-bootstrap' type='text/javascript'
src='https://openui5.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_bluecrystal'
data-sap-ui-libs='sap.m, sap.ui.commons'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<!-- define an XMLView - normally done in a separate file -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns:core="sap.ui.core" xmlns:layout="sap.ui.commons.layout" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="my.own.controller" xmlns:html="http://www.w3.org/1999/xhtml">
<OverflowToolbar>
<Title
text="Table Header Here"
level="H1" />
<ToolbarSpacer />
<Toolbar>
<Input
id="operationDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
</Input>
<Input
id="actionDelay"
maxLength="6"
type="Number"
description="ms"
fieldWidth="5rem">
</Input>
</Toolbar>
</OverflowToolbar>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
});
/*** THIS IS THE "APPLICATION" CODE ***/
// instantiate the View
var myView = sap.ui.xmlview("myView", {viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
// put the View onto the screen
myView.placeAt('content');
</script>
</head>
<body class='sapUiBody'>
<div id='content'></div>
</body>
</html>
The problem is how you apply fieldWidth...
Here is working example based on your code: https://jsbin.com/pivodos/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SAPUI5 single file template | nabisoft</title>
<script
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_belize"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"></script>
<!-- XMLView -->
<script id="myXmlView" type="ui5/xmlview">
<mvc:View
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc">
<Table>
<headerToolbar>
<OverflowToolbar>
<Title text="Table with OverflowToolbar" level="H1" />
<ToolbarSpacer />
<Input
maxLength="6"
type="Number"
description="ms"
width="10rem"
fieldWidth="50%">
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" />
</layoutData>
</Input>
<Input
maxLength="6"
type="Number"
description="ms"
width="10rem"
fieldWidth="50%">
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow" />
</layoutData>
</Input>
</OverflowToolbar>
</headerToolbar>
</Table>
<Table>
<headerToolbar>
<Toolbar>
<Title text="Table with Toolbar" level="H1" />
<ToolbarSpacer />
<Input
maxLength="6"
type="Number"
description="ms"
width="10rem"
fieldWidth="50%">
</Input>
<Input
maxLength="6"
type="Number"
description="ms"
width="10rem"
fieldWidth="50%">
</Input>
</Toolbar>
</headerToolbar>
</Table>
</mvc:View>
</script>
<script>
sap.ui.getCore().attachInit(function () {
"use strict";
//### THE APP: place the XMLView somewhere into DOM ###
sap.ui.xmlview({
viewContent : jQuery("#myXmlView").html()
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
I am having a bit of trouble setting a layout in a SimpleForm control. Here is the XML code:
<f:SimpleForm id="phoneFormSimple" editable="true" layout="ResponsiveGridLayout" title="Phone Numbers">
<f:content>
<Toolbar>
<ToolbarSpacer/>
<Button icon="sap-icon://phone" tooltip="Client Numbers"/>
</Toolbar>
<Title text="Business Phone" level="H5" titleStyle="H5"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="businessPhoneNumber" value="{business_phone_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC"
placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
<Label text="Business Extension" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<Input id="businessPhoneExtension" value="{business_phone_extension}">
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</Input>
<Title text="Business Fax" level="H5"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="buinessFaxNumber" value="{business_fax_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC" placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
</f:content>
</f:SimpleForm>
I want the third field (Business Fax) to be displayed underneath the 'Business Phone' field. Instead, it displays as such:
I'm sure I am missing something simple. Perhaps I need to use the 'Form' control instead? I tried putting an empty label as the next element, but that didn't seem to work, either. If there was a fourth field (i.e Business Fax Extension), then the layout would line up.
Any help would be appreciated! Thanks!
UPDATE:
I have taken the advice given in the answers. I was able to get the layout to work a little better, though still not quite what I want. This will probably suffice:
I added the 'core:Title' to both 'groups', though I still noticed some oddities in the layout. I removed the 'GridData' tags and I ended up with what's in the image above. I also played around with using a 'Toolbar', which had the same effect. I tried using 'core:Toolbar', but it complained that library did not exist, despite the documentation showing 'core:Toolbar' as an aggregation of the SimpleForm control. Here is the final code:
<f:SimpleForm id="phoneFormSimple" editable="true" layout="ResponsiveGridLayout" title="Phone Numbers">
<f:content>
<core:Title text="Business Phone"/>
<Label text="Number" design="Bold"/>
<MaskInput id="businessPhoneNumber" value="{business_phone_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC"
placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
</MaskInput>
<Label text="Business Extension" design="Bold"/>
<Input id="businessPhoneExtension" value="{business_phone_extension}"/>
<core:Title text="Business Fax"/>
<Label text="Number" design="Bold"/>
<MaskInput id="buinessFaxNumber" value="{business_fax_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC" placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
</MaskInput>
</f:content>
</f:SimpleForm>
Thanks for your answers! If there is any other way to have the layout like I originally wanted, additional input would be great!
EDIT: Previous answer was not completely accurate.
Even though title aggregation multiplicity is 0..1, is true that the documentation also says A new Title or Toolbar starts a new group (FormContainer) in the form.
Therefore, several options:
Option 1: Use sap.ui.core.Title instead of sap.m.Title (by #fabiopagoti)
Option 2: Delete the second title
Option 3: Add a second SimpleForm
<f:SimpleForm id="phoneFormSimple" editable="true" layout="ResponsiveGridLayout" title="Phone Numbers">
<f:content>
<Toolbar>
<ToolbarSpacer/>
<Button icon="sap-icon://phone" tooltip="Client Numbers"/>
</Toolbar>
<Title text="Business Phone" level="H5" titleStyle="H5"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="businessPhoneNumber" value="{business_phone_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC"
placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
<Label text="Business Extension" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<Input id="businessPhoneExtension" value="{business_phone_extension}">
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</Input>
</f:content>
</f:SimpleForm>
<f:SimpleForm id="faxFormSimple" editable="true" layout="ResponsiveGridLayout">
<f:content>
<Title text="Business Fax" level="H5"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="buinessFaxNumber" value="{business_fax_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC" placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
</f:content>
</f:SimpleForm>
I believe you are having trouble with your form because you are using sap.m.Title instead of sap.ui.core.Title.
Trying replacing them like this
// as is
<Title text="Business Phone" level="H5" titleStyle="H5"/>
// to be
<core:Title text="Business Phone" level="H5" />
Like this you will have different sections in your form. Check out the result without the GridData in all controls as well.
Do not forget to add the core namespace to your xml file
<mvc:View
controllerName="your.controller.name"
displayBlock="true"
xmlns:mvc="sap.ui.core.mvc"
xmlns:f="sap.ui.layout.form"
xmlns:l="sap.ui.layout"
xmlns:core="sap.ui.core"
xmlns="sap.m" >
I ended up finding out how to do exactly what I was looking to do. By adding the 'columnsM' and 'columnsL' properties to the SimpleForm control, it is now displayed in the format I want:
<f:SimpleForm id="phoneFormSimple" editable="true" layout="ResponsiveGridLayout" title="Phone Numbers" columnsM="1" columnsL="1">
<f:content>
<core:Title text="Business Phone"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="businessPhoneNumber" value="{business_phone_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC"
placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
<Label text="Extension" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<Input id="businessPhoneExtension" value="{business_phone_extension}">
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</Input>
<core:Title text="Business Fax"/>
<Label text="Number" design="Bold">
<layoutData>
<l:GridData span="XL2 L2 M2 S6"/>
</layoutData>
</Label>
<MaskInput id="buinessFaxNumber" value="{business_fax_number}" placeholder="Enter number..." mask="(CCC) CCC-CCCC" placeholderSymbol="_">
<rules>
<MaskInputRule maskFormatSymbol="C" regex="[0-9]"/>
</rules>
<layoutData>
<l:GridData span="XL4 L4 M4 S6"/>
</layoutData>
</MaskInput>
</f:content>
</f:SimpleForm>
Now the form displays as such:
Thanks to everyone who answered, it was helpful and I have a better understanding of how the form layouts work now!
Cheers!