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.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,305)