Configure an Action to Clear a View or Form
This how-to illustrates adding a rule action that clears a view, or clears multiple views on a form. For example, you want form fields cleared after someone submits the form. You might use this action as a visual indicator the form submitted successfully, or to clear fields so that someone can use the form for a new submission.
A rule that clears two views after you submit a form
Try it yourself!
This section describes how to add a rule action at the view level that clears the view fields after you click a button.
- Edit the Contact Item View. From the Rules screen, edit the When Create Button is Clicked rule.
- You see the action that create records for the view. Add the clear method action as shown below. With the Actions tab active, click Execute a method on the View to add it to the rule definition pane.
- Click select method and select Clear (no additional configuration is needed). Click OK to save the rule. Click Finish to save and exit the view.
- To test the rule action, run the view. Select the view and click Run.
- Enter content into the view fields and click Create. The view should clear after K2 creates the SmartObject record.
This section describes how to add rule actions at the form level that clears multiple views after you click a button.
- Rules defined on the form level can act on the form and views within that form. Rules defined on the view level can only act on that view. Rules in views do not have the context of the form or other views on the form.
- This section uses a form (called Contact Form) that contains two views: Contact Item View and Contact Edit List View. The form includes a submit button that creates records for both views in corresponding SmartObjects when clicked. You add two actions to the existing rule that clear both views.
- Edit the Contact Form. From the Rules tab, edit the When Submit Button is Clicked rule.
- You see two actions that create records for the item and list views. Add the clear method actions as shown below. With the Actions tab active, click Execute a View method to add it to the rule definition pane.
- Click select View and select Contact Item View. Click select method and select Clear.
- Click Execute a View method to add a second instance of the action to the rule definition pane. Click select View and select Contact Edit List View. Click select method and select Clear. You now have two methods that clear each of the views on this form. Click OK to save the rule. Click Finish to save and exit the view.
- To test the rule actions, run the form. Select the form and click Run.
- Enter content into both view fields and click Create. The views should clear after K2 creates the SmartObject records.
- Cleared content cannot be retrieved if you have not saved it in a previous rule action. If you intend to reuse content, make sure you add a rule action to create or save before clearing view fields.