πΉ Working with Forms and Custom Forms in Power Apps β A Complete Guide
π Introduction
Forms in Power Apps allow users to view, add, edit, and delete records from a data source like SharePoint, Dataverse, SQL Server, OneDrive, etc.
β Why Use Forms?
- π Allows structured data input.
- π Works with multiple data sources.
- ποΈ Supports custom validation and conditional logic.
- π¨ Can be customized for better user experience.
πΉ Step 1: Adding an Edit Form
β Insert an Edit Form
1οΈβ£ Open Power Apps Studio.
2οΈβ£ Click Insert β Forms β Edit Form.
3οΈβ£ Set the DataSource property:
DataSource = Employees
4οΈβ£ The form automatically binds to the data source and displays fields.
π Now, your form is ready for editing records!
πΉ Step 2: Configuring the Form
β Choose Form Mode
Set the DefaultMode
property to:
- FormMode.New β Create a new record.
- FormMode.Edit β Edit an existing record.
- FormMode.View β View records in read-only mode.
Example:
Form1.DefaultMode = FormMode.Edit
π This controls how users interact with the form!
β Select and Customize Fields
1οΈβ£ Click Edit Fields in the Properties pane.
2οΈβ£ Add or remove fields.
3οΈβ£ Change Data Cards order.
4οΈβ£ Customize each Data Card (Labels, Inputs, Dropdowns).
π This ensures the form displays the correct fields!
πΉ Step 3: Submitting Form Data
β Add a Submit Button
1οΈβ£ Insert a Button β Set its OnSelect
property:
SubmitForm(Form1)
2οΈβ£ To reset the form after submission, add:
ResetForm(Form1)
Navigate(SuccessScreen, ScreenTransition.Fade)
π Now, clicking the button submits data and resets the form!
πΉ Step 4: Handling Form Errors
β Displaying Errors
Forms handle validation automatically. If submission fails:
1οΈβ£ Add a Label β Set its Text
property:
Form1.Error
π This displays validation errors when submission fails!
πΉ Step 5: Creating a Custom Form
A Custom Form allows more flexibility compared to a standard Edit Form.
β Steps to Create a Custom Form
1οΈβ£ Insert Labels & Inputs Manually
- Insert Text Inputs (
txtName
,txtEmail
). - Insert Dropdowns (
ddlDepartment
).
2οΈβ£ Bind Fields to Data
Example:
TextInput1.Text = ThisItem.Name
3οΈβ£ Submit Data Using Patch Function
Instead of SubmitForm()
, use:
Patch(Employees, Defaults(Employees),
{
Name: txtName.Text,
Email: txtEmail.Text,
Department: ddlDepartment.Selected.Value
}
)
π This allows full control over form submission!
πΉ Step 6: Editing and Deleting Records
β Edit an Existing Record
1οΈβ£ Select a Gallery and set its OnSelect
:
EditForm(Form1);
Form1.Item = Gallery1.Selected
2οΈβ£ Now, the form loads the selected record for editing.
β Delete a Record
1οΈβ£ Add a Delete Button β Set OnSelect
:
Remove(Employees, Form1.LastSubmit)
2οΈβ£ This removes the selected record from the data source.
π Now, users can update and delete records easily!
πΉ Step 7: Validating User Input
β Required Fields
Set a Labelβs Visible property:
If(IsBlank(txtName.Text), true, false)
π This shows a warning if the field is empty!
β Email Validation
If(!IsMatch(txtEmail.Text, "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"), true, false)
π Ensures the user enters a valid email!
πΉ Step 8: Optimizing Performance
β Use Delegable Queries
- Avoid using CountRows(), First(), etc., on large datasets.
β Limit Data Fetch
- Set the
Items
property using Filter() to load only necessary records.
β Reduce Controls
- Too many controls can slow down the app. Use collections instead.
πΉ Step 9: Testing and Publishing
β Test the App
- Use Preview Mode (
F5
) to check form behavior. - Test on mobile & tablet for responsiveness.
β Publish the App
- Click File β Save & Publish.
π Now, your form is ready for real-world use!
πΉ Conclusion
Forms in Power Apps allow efficient data input, editing, and validation. Custom forms give developers full control over the UI and user experience.
π‘ Key Takeaways:
β
Use Edit Forms for built-in data handling.
β
Use Custom Forms with Patch()
for more control.
β
Implement validation for better data quality.
β
Optimize performance for large datasets.
Now, youβre ready to build powerful forms in Power Apps!