I am building a Canvas App on top of a SharePoint List. The app is a "sidebar" layout in which the user selects an item from the gallery in the sidebar and is then able to view and edit a number of fields in that item via a form in the main view.
The items in the gallery are filtered based in part on the value the user has selected in a dropdown menu.
A simplified version of the gallery's Items property looks like this (note that the actual code is more complicated and also involves sorting and ordering - I can provide more details if helpful but didn't think they were relevant to problem):
Switch(
gallerydropdown.SelectedText.Value,
"X",
Filter(DataSource, Field1.Value = "a", Field2.Value = "b"),
"Y",
Filter(DataSource, Field1.Value = "b", Field2.Value = "a"),
"Z")
The form's Item property is simply set as gallery.Selected.
The issue I have is that when a user makes and saves changes to an item via the form, the gallery resets and the first item in the gallery is selected by default. Obviously the form data displayed then changes as well. I would like the previously selected item to remain selected, **providing that it is still present in the gallery** (i.e., it still meets the filter conditions for the selected gallerydropdown option). If the item is no longer present in the gallery, I would like the default selected item to revert to the first item (i.e., the "normal" behaviour for a gallery).
Example behaviour I am after:
Case 1: A user selects choice "X" from the gallerydropdown. Two items are displayed in the gallery - Item 1 which is displayed first, and Item 2 displayed second. User selects Item 2 and makes changes to some fields, but Field1 and Field2 remain unchanged (i.e., the item continues to satisfy the filter conditions for the gallery when "X" is selected). When User submits these changes I would like Item 2 to continue to be selected in the gallery (rather than the selection defaulting back to Item 1).
Case 2: As above in terms of the items in the gallery, but this time the User changes the value of Field1 for Item 2 to "c". When this change is saved, Item 2 will no longer be displayed in the gallery while "X" is selected in gallerydropdown (which is currently the case). In this case, I would like the gallery selection to default to Item 1.