Working with Forms and Custom Forms

Loading

πŸ”Ή 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!


Leave a Reply

Your email address will not be published. Required fields are marked *