Hi
I have an app in which the user can choose either to "add feature" or to "edit existing feature", like shown below:
OnSelect property of "Add feature:
Set(g_featID,Blank());
Navigate(Screen2,ScreenTransition.None)
OnSelect property of "Edit Feature"
Set(g_featID,TextInput1.Text);
Navigate(Screen2,ScreenTransition.None)
Upon click, I wanted to use the same canvas-form for the two cases as:
So in the next screen, i implemented like this:
OnVisible property of Screen:
If (IsBlank(g_featID), UpdateContext({l_featMode : "Add"}), UpdateContext({l_featMode : "Edit"}));
UpdateContext({l_status : Blank()});
Refresh(TblFeatures)
Properties of the form on this screen:
DefaultMode: Switch(l_featMode, "Add", FormMode.New, "Edit", FormMode.Edit)
Item: If (Not(IsBlank(g_featID)), LookUp(TblFeatures, FeatureID=g_featID))
With this, I get correct behaviour if I add one feature:
Add feature form
Edit feature form:
But now, if I try to add another record by clicking on "add feature", the form is stuck as "No item to Display":
Note that the first record is added successfully as can also be seen in the excel table.
To me, it looks like a bug!
Will appreciate any support/workaround in this issue.
(unfortunately, I cant export and share app package due to corporate restrictions)
Thanks.
Solved! Go to Solution.
I think you made it much more complicated than it needs to be. Powerapps forms usually reference a datatable or a gallery. So normally there is a Datatable or Gallery on the first screen. Forms can either create a record in a datasource, edit one already created or view one (read only). You set the default Form mode using the functions EditForm(Form1), NewForm(Form1) and ViewForm(Form1) before you navigate to the second screen containing the Form. So if the form is on a different screen, you could set up your buttons on your first screen, say Add, Edit . The Add button OnSelect property would be NewForm(Form1), Navigate(Screen2,ScreenTransition.None), The Edit button would be EditForm(Form1),Navigate(Screen2,ScreenTransition.None) Putting the edit button inside the gallery will automatically select the record to edit. The Add button can be outside the gallery because a new form is being created.
On the 2nd screen, there would be an Edit form control. Its Datasource property would be the same as the datasource of the gallery or datatable. Its Item property would be Gallery1.Selected. (The Item property is ignored if the form is in New mode). On the second screen, You would have a button for Submitting the form with the OnSelect property SubmitForm(Form1) in the picture below it is the check mark. The X icon OnSelect property would be ResetForm(Form1);Back(None). so you could go back if you decided not to edit the record. In the OnSuccess property of the form you could put Back(None) and after submitting your property, the app would navigate back to the first screen and your new or edited item would be displayed in the gallery or datatable. I hope this helps. In the example below, I edited Adrian's record by adding Unknown in the Status box. After clicking the check mark, The form navigated back to the Gallery screen and the new status is shown.
Screen 1
After clicking edit on Adrian
After saving Adrians status as Unknonw
I think you made it much more complicated than it needs to be. Powerapps forms usually reference a datatable or a gallery. So normally there is a Datatable or Gallery on the first screen. Forms can either create a record in a datasource, edit one already created or view one (read only). You set the default Form mode using the functions EditForm(Form1), NewForm(Form1) and ViewForm(Form1) before you navigate to the second screen containing the Form. So if the form is on a different screen, you could set up your buttons on your first screen, say Add, Edit . The Add button OnSelect property would be NewForm(Form1), Navigate(Screen2,ScreenTransition.None), The Edit button would be EditForm(Form1),Navigate(Screen2,ScreenTransition.None) Putting the edit button inside the gallery will automatically select the record to edit. The Add button can be outside the gallery because a new form is being created.
On the 2nd screen, there would be an Edit form control. Its Datasource property would be the same as the datasource of the gallery or datatable. Its Item property would be Gallery1.Selected. (The Item property is ignored if the form is in New mode). On the second screen, You would have a button for Submitting the form with the OnSelect property SubmitForm(Form1) in the picture below it is the check mark. The X icon OnSelect property would be ResetForm(Form1);Back(None). so you could go back if you decided not to edit the record. In the OnSuccess property of the form you could put Back(None) and after submitting your property, the app would navigate back to the first screen and your new or edited item would be displayed in the gallery or datatable. I hope this helps. In the example below, I edited Adrian's record by adding Unknown in the Status box. After clicking the check mark, The form navigated back to the Gallery screen and the new status is shown.
Screen 1
After clicking edit on Adrian
After saving Adrians status as Unknonw
Hi @saurm
actually @Drrickryp, was right about about complicating simple things!
since PowerApps started using DisplayMode property i started using only a single form for both editing and viewing.
so here's what i suggest you do:
try it out and let me know if it is successfull.
regards,
Mohammad
@Drrickryp, Thanks for introducing me to EditForm, NewForm and ViewForm functions.
and saving me from extra complexity - appreciate it.
@mokhawaja The step 4 shared by you was quite useful to improve my actual app's behavior...
Thanks for step by step details
I was totally stumped on this one! Finally came across this post.
I'd had Select(Parent) where I should have had ViewForm(frmRequest_1). No matter what I did, my form was always in Edit mode when I selected it from the gallery. When I used ViewForm...it took care of things! Thanks ever and ever so much!