web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / DefaultMode in a canva...
Power Apps
Unanswered

DefaultMode in a canvas app form

(0) ShareShare
ReportReport
Posted on by

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)

 

 main page.PNG

 

 

Upon click, I wanted to use the same canvas-form for the two cases as:

  • for "Add feature" the form should be in FormMode.New
  • for "edit feature" the form should be in FormMode.Edit

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

 

add feature_1.PNG

 

add_feature_2.PNG

 

Edit feature form:

edit_feature.PNG

 

 

 

 

But now, if I try to add another record by clicking on "add feature", the form is stuck as "No item to Display":

 

add_feature_3.PNG

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.

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous,

    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 1Screen 1After clicking edit on AdrianAfter clicking edit on AdrianAfter saving Adrians status as UnknonwAfter saving Adrians status as Unknonw

     

     

  • mokhawaja Profile Picture
    239 on at

    Hi @Anonymous

    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:

    1.  go to insert>form>edit to insert your editform.
    2. it is best practice to always link the form.item property to a gallery.selected or data table, or even dropdown or combo box.
    3. change the form.DefaultMode property to FormMode.View
    4. change the form.OnSuccess property to: ViewForm(FormName)
    5. Change the form.OnReset property to: ViewForm(FormName)
    6. OnSelect property of "Add feature: NewForm(FormName);Navigate(Screen2,Transition.none)
    7. OnSelect property of "Edit feature: EditForm(FormName);Navigate(Screen2,Transition.none)
    8. OnSelect property of the Check icon: SubmitForm(FormName);Navigate(Screen1,Transition.none)

    try it out and let me know if it is successfull.

     

    regards,

    Mohammad

  • Community Power Platform Member Profile Picture
    on at

    @Drrickryp, Thanks for introducing me to EditForm, NewForm and ViewForm functions.

    and saving me from extra complexity - appreciate it.

  • Community Power Platform Member Profile Picture
    on at

    @mokhawaja The step 4 shared by you was quite useful to improve my actual app's behavior...

    Thanks for step by step details

     

  • mokhawaja Profile Picture
    239 on at

    thanks @Anonymous, glad you solved your issue!!

  • CindyZ Profile Picture
    on at

    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!  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard