cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to clear the selection in a Gallery after submitting a form

Hello,

I have a tablet layout powerapp with one MyScreen. The Screen contains MyGallery, MyForm, CancelIcon and SubmitIcon. I like to select an Item in the MyGallery and edit in MyForm. When clicking the CancelIcon or SubmitIcon, the selection in MyGallery should be cleared.

 

I have it working except the Submit part. Once I submit an Item, I can't clear the Gallery selection anymore. 

 

in MyScreen.OnVisible / MyScreen.OnHidden / CancelIcon.OnSelect, I use the following to clear the selection in MyGallery:

UpdateContext({MySelection: MyGallery.Selected}); UpdateContext({MySelection: {}})

To make this work, MyGallery is configured to

MyGallery.Default = MySelection

 

It seems to work like a charm. MyGallery shows all items but none is selected. When I select an item, it shows in MyForm by using

MyForm.Item = MyGallery.SelectedItem

When I click on the CancelIcon it resets MyGallery and the MyForm got nothing to show.

 

Once I submit the form using SubmitIcon.OnSelect:

SubmitForm( MyForm ) 

Now resetting the gallery doesn't work anymore, instead the last Submitted item is selected. Even if I select another item and click on CancelIcon, the last submitted item is selected.

 

Any suggestions how to make this work? Maybe a different approach?

 

Cheers,

Dennis

1 ACCEPTED SOLUTION

Accepted Solutions
Sienna
Memorable Member
Memorable Member

Hi

The only way of doing it is a bit drastic but it works however it also reset your form so you will have no items in the form. I would suggest you to get rid of the form, and make your own form with textinputs and labels items and use the patch function to edit the record. If you will have problem with doing that then let us know. 

 

So to the point now...  change your code in your cancel icon in OnSelect property

UpdateContext({reset:true}); UpdateContext({reset:false}); UpdateContext({MySelection: MyGallery.Selected}); UpdateContext({MySelection: {}})

Do the same thing in your MyScreen.OnVisible

 

Then in your gallery Items add this

If(reset=false,MyDataSourceName)

Obviously change the MyDataSourceName with the datasource you are using in your gallery

 

This will reset the whole gallery and make the deselecting code works again

View solution in original post

3 REPLIES 3
Sienna
Memorable Member
Memorable Member

Hi

The only way of doing it is a bit drastic but it works however it also reset your form so you will have no items in the form. I would suggest you to get rid of the form, and make your own form with textinputs and labels items and use the patch function to edit the record. If you will have problem with doing that then let us know. 

 

So to the point now...  change your code in your cancel icon in OnSelect property

UpdateContext({reset:true}); UpdateContext({reset:false}); UpdateContext({MySelection: MyGallery.Selected}); UpdateContext({MySelection: {}})

Do the same thing in your MyScreen.OnVisible

 

Then in your gallery Items add this

If(reset=false,MyDataSourceName)

Obviously change the MyDataSourceName with the datasource you are using in your gallery

 

This will reset the whole gallery and make the deselecting code works again

View solution in original post

Anonymous
Not applicable

Hi Sienna,

I did an alternative way, by using a variable, e.g. SelectedGalleryItem, instead of Gallery.Selected. That has the disadvantage, that I have to iimplement the selection logic and the built-in selection logic doesn't work, e.g. Gallery.Selected and ThisItem.IsSelected.

 

Anyway ... Thanks a lot, your solution works for me. Resetting the form is not an issue, as I am hiding the form after it has been submitted. I did attach the reset-toggle only to the SubmitIcon and DeleteIcon, as only they caused that the MyGallery.Selected got stuck.

 

I think it can't be by design that submitting a form gets the Gallery.Selected misterically stuck. Is there a way to report this as a bug?

 

Cheers,

Dennis

Sienna
Memorable Member
Memorable Member

I’m happy to help. About reporting bugs.. Im usualy getting this aswer when I spot something or want to ask about someting so I asume that it will be ok for reporting bugs

Thanks for your feedback, and please consider to add an new idea in PowerApps idea forum for such feature request issue.
https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

Helpful resources

Announcements
User Groups Public Preview

Join us for our User Group Public Preview!

Power Apps User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (28,691)