cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Axal
Super User
Super User

How to make a blank Edit Form

Hello guys,

 

I have a request that on my Edit Form, which are contain several fields (data cards) to have behavior like an edit existing record and also insert new record.

 

For edit existing I'm using that Edit Form - Item property to refer to my Gallery1.selected. However am still confuse how to make it able to insert new record, like make all the fields blank ? I put a button to set a variable like :

Set(newLine,true)

 

Then in that Edit form - Item property I added some logic like this :

If(newLine = false,
Gallery1.Selected,
Blank()
)

 

Seems not working as it will be blank as no control appears. What I'm expected is all the control still appears but empty value for me to key in then insert a new record. Is that possible ?

 

Kindly advice,

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

You are correct - the NewForm function must refer to the form control, not the underlying datasource. Sorry for that confusion.

 

I believe you are seeing the expected behavior - when the Form is in FormMode.New you will see empty fields for entry, except in cases where you deliberately changed the Default property to show something else. Note that individual controls within the form typically show Parent.Default, which refers to the Default property of the parent card for the form. 

 

While the form is in FormMode.New, selecting an item from the other gallery will not alter the displayed contents of the cards. The form is ready to create a new record, not edit an existing one. If you want to go back to editing, EditForm() will get you there.

 

For your code: If(newLine = false, Gallery1.Selected)

Consider using the form's mode for logic in the app. Form1.DefaultMode = FormMode.Edit evaluates to false after a call of NewForm(Form1)

 

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

View solution in original post

6 REPLIES 6
BCLS776
Super User
Super User

It sounds as though you want to use the NewForm() function instead. This puts your form into FormMode.New, with blank/default entries in preparation for a whole new record. Is that what you are after?

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Hi @BCLS776 ,

 

I'm afraid no (unless I'm not really understand how this PowerApps works). But the Form it self contain more than 1 data source, will the FormMode.new makes my Edit Form blank ?

 

This Edit form that I want to make it empty controls is an Edit form for 1 of my data sources, while the other data source will stay as it the current record.

 

For some illustration will be something like this :

Axal_1-1626121482551.png

So, whenever user select on row of the Data table (gallery) at the bottom, the Edit Form (which is in the middle) is populated with record selected. I will have Update button to update the existing record (not displayed on my sample)

 

But if user click New Line button (in yellow), the Edit Form will all have empty value for user to key in. Then Insert as new record. I will have Insert button (not displayed on my sample)

 

Hope it is make sense.

Thanks

 

 

 

Yes, in the OnSelect property of the New Line button, put NewForm(DataSourceB)

 

Then, use the Default property of the various cards in the form to control what you want there or what you want to be left blank for the user to enter. For example, the card connected to Order ID for DataSourceB can have a Default value of DataSourceA.SelectedItem.OrderID, which will populate the field with the currently-selected order ID from the first gallery.

 

Finally, add a button or something similar, with an OnSelect of SubmitForm(DataSourceB) that the user can use to save the form entry as a new record in the database. This may be the "insert" button you are describing?

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Hi @BCLS776 

 

Thanks, I think I'm getting somewhere here. With your advice, I've put NewForm(EditFormName), I thought this is correct, right? because it need Form instead data source. And because those controls inside my Edit Form has Defaulted to Parent.Default, am I correct to say I don't need to put any addition code ?  beside of course the Order ID.

The form (or the controls) is appeared with empty value now, however something odd, that now while the original Item property of this Edit Form is Gallery.selected, now it won't displayed, when it is Play (run) I even click the gallery but the EditForm still empty.

 

I still put the Set variable ("newLine"), btw in that NewLine button, to have a "flag" when it is click then the Variable turns "true" I put the same in App.Start to put as "false". And in that Edit Form - Item property I put -> 
If(newLine = false,
Gallery1.Selected)

 

But somehow it didn't effect. The edit form stay empty.

 

Thanks

 

 

You are correct - the NewForm function must refer to the form control, not the underlying datasource. Sorry for that confusion.

 

I believe you are seeing the expected behavior - when the Form is in FormMode.New you will see empty fields for entry, except in cases where you deliberately changed the Default property to show something else. Note that individual controls within the form typically show Parent.Default, which refers to the Default property of the parent card for the form. 

 

While the form is in FormMode.New, selecting an item from the other gallery will not alter the displayed contents of the cards. The form is ready to create a new record, not edit an existing one. If you want to go back to editing, EditForm() will get you there.

 

For your code: If(newLine = false, Gallery1.Selected)

Consider using the form's mode for logic in the app. Form1.DefaultMode = FormMode.Edit evaluates to false after a call of NewForm(Form1)

 

 

_________________________________________________________________________________________
Help the community help more users by choosing to "Accept as Solution" if this post met your needs. If you liked the post and want to show some appreciation, please give it a Thumbs Up.

Hi @BCLS776 

 

Thank you very much for all your guidance. All is works as expected now. 😀

 

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,437)