Usage Scenario
You want to add two date fields to the subsection and they must have a calendar in the value help dialog. Also, you want to extend the single input field to a multiline input field. In addition, add a placeholder text which is shown if the field is empty.
Task Flow
In this exercise, you will perform the following tasks using the Page Editor:
- Add two fields of the type date to the subsection of the object page.
- Change the type of the input field and add a placeholder text that is displayed when the field is empty.
Prerequisites
You have completed the exercise Use the Singleton Entity for Constant Values of the Bullet Micro Chart in the unit Shaping the Header Area of the Object Page (lesson: Using the Singleton Entity). Alternatively, you can check out its solution branch: solution/use-singleton-for-bullet-micro-chart-on-op.
Watch the Simulation and Perform the Steps
This exercise contains a simulation that takes you through all the steps described below. You can follow the simulation and perform the steps using your own trial account.
Steps
Open your CAP project in SAP Business Application Studio.
In the Explorer view, select Projects\app\webapp.
Right-click on webapp and select Show Page Map. The Page Map of the Travels application appears.
Choose the Edit icon of the Travel object page. The Page Editor of the TravelObjectPage appears.
Add two date fields in the General Information subsection.
In the Page Layout, under Sections, expand General Information.
Expand Subsections\General Information\Form\Fields.
Choose Add.
Choose Add Basic Fields. The Add Basic Field dialog appears.
From the dropdown, select BeginDate and EndDate.
Choose Add. The fields End Date and Starting Date appear in the control tree of the Page Editor.
Note
In the right pane, the user can see the settings that they can change for the selected field.
Change the type of the Description field to multiline. Add a placeholder text to it.
Perform step 1 and sub-steps a to b of step 2.
Choose Description.
In the right pane, under Display Type, choose the dropdown.
Select Text Area.
Choose the Edit in source code icon. The layout.cds file appears. The @UI.MultiLineText annotation is generated by the Page Editor.
Add the @UI.Placeholder annotation to the @UI.MultiLineText annotation.
Code Snippet1234annotate TravelService.Travel with { Description @UI.MultiLineText: true @UI.Placeholder : '{i18n>DescrPlcehlder}' }In the Explorer view, select Projects\_i18n\i18n.properties. The i18n.properties file opens. Add the following placeholder text to the file:
Code Snippet1DescrPlcehlder=Put your description for the travel
View the two date fields in the Manage Travels application.
Open the Manage Travels application. In the General Information subsection, you can see the fields End Date and Starting Date.
Choose Edit.
Choose the calendar icon corresponding to the End Date field.
Result
The calendar is automatically added as a value help to the input fields of type Date.
Note
You can see in the solution branch for this exercise that the Page Editor has added two values of type
UI.DataField
to the existing annotation for the subsection (@UI.FieldGroup#TravelData
).View the multiline input field and placeholder text for the Description field.
Open the Manage Travels application.
Choose Edit.
Result
The single input field is extended to multi-line text field. Also, if the text field is empty, you can see the replaced with the newly added placeholder text, Put your travel description here.
Result
In this lesson, you have learned to add a field to a section or subsection on the object page with the help of the Page Editor. You can also change the settings for the fields such as a field label, a field type, and add restrictions using the Page Editor.
Note
You can find the solution for this exercise on GitHub.
- The solution branch is solution/add-date-multiline-text-placeholder.
You can see the code changes compared to the previous branch on GitHub.
Next Steps
For more information, see