Configure the Set a View's Properties Action
Use the Set a View's properties action when you want to change the properties of a view at runtime. For example, you may have a form used for registering new students as well as entering results after the student completes a course. By setting a view's Visible property, you can hide or show the views you want for the different ways the form is used.
Example: In the image below, you see the Student Registration Form (in design time) with three views: Student Details Item, Add Student Course Results, and Saved Student Course Results. To register new students, you show the Student Details Item view and hide the other two views. To enter results for courses completed, you show all three views.
Try it yourself!
Find the Set a View's properties action in the Form Interaction group.
Rule Breakdown
In this example, you hide the course results views for the (Base State). (The base state controls the form's look and behavior for registering new students.) You add an action to the form initializing rule that hides the Add Student Course Results and Saved Student Course Results views when the form is loaded.
- Events define when the rule should run, such as when a button is clicked, or when the form loads. (Events are optional, you can define "event-less" rules that you can call from other rules.)
- Conditions define whether the rule should run. If the criteria are true, continue the rule, and if the criteria are not met, stop the rule. For example, a condition might evaluate a form to confirm that required fields have content. (Conditions are optional - not all rules will require conditions.)
- Actions define what the rule should do. For example, show a message, start a workflow, or enable a form field. Rules can contain multiple actions that are run in sequence or in parallel.
Form
Follow the steps below to configure the Set a View's properties action for the (Base State) of the form.
- Edit the Student Registration Form and open the Rules screen.
- Edit the When the Form is Initializing rule for the Student Registration Form > (Base State).
- With the Actions tab active, click Set a View's properties to add it to the rule definition pane. Click select View and select Add Student Course Results.
- With the Actions tab active, click Set a View's properties to add a second instance of the action to the rule definition pane. Click select View and select Saved Student Course Results. You should now have two actions, one for each course results view.
- Next, you configure the properties you want to set. You will repeat this process for both actions. Click (configure) for the Add Student Course Results action.
- You want to hide this view for the (Base State), since you are registering the student for the first time and they have not taken any courses yet. Therefore, the student does not have any course results to enter. Check the Visible box and select No. Click OK to save the setting.
- Repeat the step above for the Saved Student Course Results view. Set the Visible property to No and click OK to save the setting.
- Your rule actions should look like the image below. Click OK to save and exit the rule designer. Click Finish to save and exit the form.
- To test the rule actions, open the form using the Runtime URL found in the central pane. The form opens with the default (Base State) where you hid the two course results views. You only see the Student Details Item view.
In the rule definition pane on the right side of the screen, you see three actions that initialize, or load, the three views on the form. As you add views to a form, K2 adds the initialize actions for you. You will add actions below and configure them to hide two of the views.
There are two sections to the Set a View's properties configuration screen: Mapping Destinations and Context Browser. In the Mapping Destinations section, you can set the view's title and visibility, as well as enable or disable the view, expand or collapse the view, and set the default view display. See the table below the image for an explanation of each setting. The Context Browser contains references, variables, functions, and SmartObject properties. At runtime, K2 replaces references and variables with live data. In this way, you can personalize your content.
Property | Settings | Notes |
---|---|---|
Detail | ||
Name | Text | This is the file name of the view. You cannot set this property at runtime. |
General | ||
Title | Text | Check this box to activate the property. Use this setting to generate a Title for the view. You can manually enter a title for your view, or use a value from the Context Browser. |
Tab Index | Number | The tab index refers to the order in which tabbed views are navigated using the tab key on your keyboard. You cannot set this property at runtime. |
Visible | Yes/No | Check this box to activate the property. Select Yes to show the view on the form or No to hide the view. |
Enabled | Yes/No | Check this box to activate the property. Set Enabled to No to 'lock' a view so that the user cannot interact with the view or enter data. This is often used to present read-only versions of a view. Set Enabled to Yes to allow the user to interact with the view, such as entering data on the view. |
Collapsible | Yes/No | Check this box to activate the property. Select Yes to allow someone to collapse the view on the form. Select No to keep the view either expanded or collapsed. |
Default | Expanded/ Collapsed | Check this box to activate the property. Select Expanded to render the view expanded when the form opens. Select Collapsed to render the view collapsed. |
Width | Text | Sets the view's height. You cannot set this property at runtime. |
Height | Text | Sets the view's width. You cannot set this property at runtime. |
Display | ||
Format | Sets the view's format (border, padding, font). You cannot set this property at runtime. |
In this example, you edit the form initializing rule for the Add Results state to show the two views hidden on the default state. Any rule events, conditions, and actions applied to the default (Base State) automatically apply to any subsequent states. Therefore, the two views previously hidden in the base state's form initializing rule are also hidden in the Add Results state.
- Edit the Student Registration Form and open the Rules screen.
- Edit the When the Form is Initializing rule for the Student Registration Form > Add Results state.
- You see the two Set a View's properties actions you added earlier to the (Base State). Remember, the actions hide the two course results views. You want to show the two views for the Add Results state. You can accomplish this by disabling the two hide actions. Hover over the then set the properties of Add Student Course Results View action until you see the toolbar. Uncheck the Enable/Disable Item box.
- Repeat the step above for the then set properties of the Saved Student Course Results View action. Click OK to save the rule. Click Finish to save and exit the form.
- To test the form, you need to run it using the Add Results state. (Remember, the default state is (Base State).) To change the states for testing the form, click Run with Parameters found in the central pane.
- Because there is more than one state, K2 adds a parameter called Form State. You can select a state from the Value drop-down list. The form runs using the rules from the selected state. Select Add Results and click Run.
The form opens and you see all three views.
- To change the form's properties at runtime, see Configure the Set a Form's Properties Action