Power Apps Forms – Form Mode
Updated: May 21, 2021
Microsoft Power Apps forms are a way to edit and enter new data easily, but sometimes the nuances of form mode can be difficult to navigate.
This tutorial provides an in-depth breakdown of data manipulation in Microsoft Power Apps using forms. By taking a closer look at the subtle nuances of this key utility, users will learn to expand the functionality of their applications and improve user experience. Power App’s forms provide valuable solutions for business owners, operations managers, team leads, and others. Follow along with the video to see examples in action.
How to Set Power Apps Form Mode
The primary purpose of a form is to give and receive data to a source. The real benefit of forms is the ability to choose the exact fields you wish to view or edit and have all of the appropriate labels and input controls generated for you with little effort. The form mode tells the form how to communicate with the datasource. Do you wish to view a record, edit and existing record, or create a whole new one?
Change the Form’s Default Values
The form’s default values provide granular control over the form by setting the form mode without specifying it elsewhere. In other words, the form will default to this mode unless otherwise commanded.
To change the default form mode, follow these steps:
With the form selected, select “DefaultMode” in the properties dropdown on the top left. To select the whole form, you may need to use the tree view on the far left panel.
The command bar should read FormMode.Edit. Adjust the “FormMode” function to change the value.
Delete the “Edit” line from the command bar and Power Apps will display a selection to choose from. These include “Edit”, “New”, and “View”. Set the default form mode according to your desired default.
Now the form cannot be altered unless the form mode is changed.
Add a Button to Edit Forms
Setting the default form mode is a good start, but users still need a way to easily change the form mode from the default setting.
To do this, insert a button and name it “Edit”. Now try clicking it. The button won’t do anything yet.
In the command bar for the OnSelect property, type EditForm(Form1) with “Form1” as the name of the form. Select the button to expose the form properties for editing.
This is a simple way to switch modes in Power Apps forms on the fly.
Add a Button to Cancel Editing
Create another button and change the text to Cancel.
Type ViewForm(Form1) into the command bar for the OnSelect property. With the form mode in edit, select the new button. Remember that you can hold down the Alt key or put the app in play mode to mimic a user role. The mode will now switch back to view mode.
Users can now easily toggle through the two modes.
Hide or Show Cancel Button
With the cancel button still selected, find the Visible property in the dropdown and type Form1.Mode = FormMode.Edit into the command bar. This will force the cancel button to show only when the form is in edit mode. You may be tempted to write an If statement here, but remember that this is unnecessary for expressions in which the desired outcome is true or false.
Add a Button to Create New Item
Create another button and name it “New.” With the button selected, type NewForm(Form1) into the command bar for the OnSelect property. Click the button to create a new form. This works fine, but the cancel button still isn’t displayed. This is because our Visible logic for the cancel button is looking to see if form mode is edit, and right now the form mode is new.
Go back to the Visible property for the Cancel button. You have two options to set the logic here. The first is to show the button if the form mode is not view. For this, type into the formula bar!(Form1.Mode = FormMode.View). Note that the exclamation point means Not and results in the opposite of the condition specified. The second option is to point to the display mode for the form. Although their are 3 form modes, there are only 2 display modes, view and edit. This can be confusing, but consider how in both edit and new form the inputs are allowed to be set or changed; in view they are not. The logic for this formula would be Form1.DisplayMode = DisplayMode.Edit.
Add a Button to Save Forms
Create one more button.
Name it “Submit or Save” and type SubmitForm(Form1) into the command bar for the OnSelect property.
This will allow users to create, edit, and save new forms in individual clicks.
Learn More about Power Apps Form Mode with PowerApps911
Conditional formatting with Power Apps forms can be difficult to understand, but when used correctly, these building blocks can provide numerous solutions for data manipulation and storage.
Check out our expert courses and lessons for more step-by-step guides!