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

Reset Gallery Selection Not Working With Patch

I have a gallery that displays a list of items for users to select and then use separate controls to edit. When they click on an item, it sets a context variable editVis_ to true, which reveals a group of text inputs to change the details of the item. It also reveals a cancel icon that can be used to exit and unselect the item in the gallery. When they edit an item, it patches the new values to the data source. Once they are done editing the item, I would like them to be able to select the cancel icon to reset the gallery with no items selected.

 

I tried the solutions in this post both by setting the default of the gallery to a context variable defaultSel_ and then adding the line

UpdateContext({defaultSel_: gallery.Selected}); UpdateContext({defaultSel_: {}}); 

to the cancel icon and setting the default of the gallery to {} and using

Reset(gallery)

in the cancel icon.

 

Both of these solutions work until I patch an update to the source list. Once I patch an update to an item, it is set as the default selection no matter what I do. Even if I set up a separate button with the code above, it still resets to select the last item that was patched. Is there something wrong with my code, or is this a bug with PowerApps?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @Anonymous ,

Do you mean that if you firstly choose an item, then patch a new item, then click the cancel button, the selected item will not change to blank?

I've made a similar test and met the same problem like your description.

However, I found that if I refresh the data source after I patch the new item, this problem will not exist.

So I think this should be about data refreshing.

I know it's complicated to refresh the data source every time you patch.

So I figure out an alternative way to solve this problem.

 

Maybe you could refer this:

1)set the arrow button inside the gallery

OnSelect: 

Set(var_reset,false)

2)set the cancel button's OnSelect:

UpdateContext({defaultSel2_: Gallery2.Selected}); UpdateContext({defaultSel2_: {}});Set(var_reset,true)

you could also use:

Reset(Gallery2);Set(var_reset,true)

3)set the form's Item:

If(var_reset,defaultSel2_,Gallery2.Selected)

 

In this way, you could use variable to justify whether you cancel selected item.

And in this situation, variable will not be affected by the patch function.

 

1030.PNG

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Highlighted
Community Support
Community Support

Hi @Anonymous ,

Do you mean that if you firstly choose an item, then patch a new item, then click the cancel button, the selected item will not change to blank?

I've made a similar test and met the same problem like your description.

However, I found that if I refresh the data source after I patch the new item, this problem will not exist.

So I think this should be about data refreshing.

I know it's complicated to refresh the data source every time you patch.

So I figure out an alternative way to solve this problem.

 

Maybe you could refer this:

1)set the arrow button inside the gallery

OnSelect: 

Set(var_reset,false)

2)set the cancel button's OnSelect:

UpdateContext({defaultSel2_: Gallery2.Selected}); UpdateContext({defaultSel2_: {}});Set(var_reset,true)

you could also use:

Reset(Gallery2);Set(var_reset,true)

3)set the form's Item:

If(var_reset,defaultSel2_,Gallery2.Selected)

 

In this way, you could use variable to justify whether you cancel selected item.

And in this situation, variable will not be affected by the patch function.

 

1030.PNG

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (3,397)