cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
v-yutliu-msft
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
v-yutliu-msft
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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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