cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Wahv
Frequent Visitor

Merging New Form and Edit Form Screen Into One

Problem: While developing power apps, I often find myself making a screen where the user can create a new form and a screen where a user can edit an already existing form. The edit form screen in my case would be completely identical to the new form screen, so a problem I constantly face is whenever I make changes to my new form screen, I either need to make the exact same changes to the edit form screen or duplicate the new form screen. This process works, but I would like a more efficient approach.

 

Question: Is it possible to merge my new form screen and my edit form screen into one single screen? I'm struggling to figure out a way for my forms to display default information in the case of a new form and display the selected values in the case of editing forms. Additionally, I want to make sure I am saving changes to selected entries instead of creating a new form with the desired changes. Does anyone have any sage wisdom on how to accomplish this or should I stick with having two seperate screens?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Drrickryp
Super User
Super User

@Wahv 

You can use NewForm(Form1) and EditForm(Form1) with the Navigation() function that changes screens.  Typically a button outside a gallery would have NewForm(Form1);Navigate(scrYourForm) to set the mode of the form and an icon Inside the gallery would have EditForm(Form1);Navigate(scrYourForm) as its OnSelect property.  That way the form could be used for creating a new record as well as editing a selected record.  

The form should have its Item property Lookup(yourdatasource, ID=yourgallery.Selected.ID).  When the form is in New mode, this is ignored because the record doesn't exist until the form is submitted,  but when it is in Edit mode, this is how the form knows which record to edit.  

View solution in original post

3 REPLIES 3
Drrickryp
Super User
Super User

@Wahv 

You can use NewForm(Form1) and EditForm(Form1) with the Navigation() function that changes screens.  Typically a button outside a gallery would have NewForm(Form1);Navigate(scrYourForm) to set the mode of the form and an icon Inside the gallery would have EditForm(Form1);Navigate(scrYourForm) as its OnSelect property.  That way the form could be used for creating a new record as well as editing a selected record.  

The form should have its Item property Lookup(yourdatasource, ID=yourgallery.Selected.ID).  When the form is in New mode, this is ignored because the record doesn't exist until the form is submitted,  but when it is in Edit mode, this is how the form knows which record to edit.  

timl
Super User
Super User

@Wahv 

To add to what @Drrickryp (which is the answer to this question) here's how to address this point:

 

>> I'm struggling to figure out a way for my forms to display default information in the case of a new form and display the selected values in the case of editing forms

 

The Default property of a control (eg text input control) on an edit form will be set to Parent.Default. If you modify this value on your combined form so that it checks the form mode, you can display the existing value in edit mode, and apply a default value in new mode.

If(CombinedForm1.Mode = FormMode.Edit,
   Parent.Default,
   "TheDefaultValueYouWantToShow"
)
Drrickryp
Super User
Super User

@timl  is right of course.  However, I prefer Coalesce(Parent.Default, "TheDefaultValueYouWantToShow" ).  It's more concise and has the same result as the If(... statement.  It works because in a New form, the Parent.Default is blank.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,136)