5. Add the List View to a Form
In this step, you add the new List Hello World view to the Display Hello World form. You add a tab to the form that creates a sub-form. Next, you add the list view to the new tab form. You can click this tab and see a display of the Hello World list items.
-
Edit the Display Hello World form. Add a new tab to the form with the title Hello World List Items.
- From the K2 Application elements page, edit the Display Hello World form.
- On the LAYOUT screen, click the Add button found in the Tab pane, to add a new tab to the form.
(Note: If you do not see the Tab: Add button, it's possible your screen is too narrow. In this case, you will see a drop-down arrow to the right of the row. Click the arrow, then select Add Tab.)Tabbed views and why would you use them? Adding a tab to a form adds a new form canvas. You can add views and controls to the new form canvas and adjust rules as well. This creates a clean way to add additional views to a form without compromising the primary form's functionality. You can use tabbed views for data entry or to display content, as you are in this step.Adding too many tabbed views to a form can have an effect on performance. One workaround is to add a rule that only loads data in the tabbed view when the user exposes the view. This way, the form only loads data that is being used. - You should now see a tab called HELLO WORLD with a new-tab icon to the right of it. Click the new tab icon, then click the (ENTER TAB TITLE) title and change it to:
Hello World List Items
then click outside of the title box to set the title.
- From the K2 Application elements page, edit the Display Hello World form.
-
Add the List Hello World view to the new tabbed form canvas. Add a new action to the form initialize rule that executes the List Hello World > Get List Items method. There are no other configurations, as you want the entire list to load without filters.
- You now have a new canvas that you can add views to. You can also add a layout table and controls, but since you have the list view created, you will add it to the new canvas.
Click the Views tab to switch to the category browser. Drag the List Hello World view onto the design canvas. - Next, add a rule action that executes when the form loads. This action retrieves the records from the Hello World SmartObject. Click the RULES tab. Select the When the Form is Initializing rule and click Edit Rule.
- Confirm the Actions tab is active. Click Execute a View method (under the SmartObject Interaction heading) to add it to the rule definition pane.
- Click the select View link and select List Hello World. Click the select method link and select Get List Items. There are no other configurations, so click OK to save the new action.
- Click FINISH to save and exit the tabbed form.
- You now have a new canvas that you can add views to. You can also add a layout table and controls, but since you have the list view created, you will add it to the new canvas.
Review
In this step, you added a new list view to an existing form. Users cannot access views directly, they must be part of a form. You can add more than one view to a single form canvas and you can add tabs, which you did in this exercise. Views are reusable. You can use a single view in several forms. For example, you can create a view that contains employee details (such as name, department, email), then use the view in all your forms for consistency. Any updates to the view roll out to all the forms using the view. In the next step, you will check in the views and forms to publish their changes to the K2 server.