cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
starwispy
Kudo Collector
Kudo Collector

Help please! Reset search and retain focus

Where a search box exists on 2 separate screens, is it possible to either:

 

  1. Use a single BrowseScreen that can filter the gallery using either searchbox, without conflict; OR
  2. Set focus on the TextSearchBoxSecondary when the user navigates to this screen, so they don't have to click into it again in order to type.

 

BACKGROUND AND EXPLANATION BELOW:

 

I have an app connected to a SharePoint list, where users can search for meeting rooms based on the meeting room name (Title) or the room facilities (Equipment).  The search box (TextSearchBoxWelcome) is located on the WelcomeScreen, and directs users to BrowseScreenSearch when the Go button is pressed.

 

WelcomeScreen:

 

WelcomeScreen.png

 

BrowseScreenSearch:

 

BrowseScreenSearch.png

 

The Items property for the BrowseGallery on BrowseScreenSearch is set to:

SortByColumns(Filter(MeetingRoomsPowerApp, TextSearchBoxWelcome.Text in Title || TextSearchBoxWelcome.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending))

 

This works great, however I'd like users to then be able to change their search terms using the search box on this screen (TextSearchBoxMain).  I believe this should work if I change the Items property to:

 

If(TextSearchBoxWelcome.Text<>"",SortByColumns(Filter(MeetingRoomsPowerApp, TextSearchBoxWelcome.Text in Title || TextSearchBoxWelcome.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending)),SortByColumns(Filter(MeetingRoomsPowerApp, TextSearchBox1_1.Text in Title || TextSearchBox1_1.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending)))

 

HOWEVER the problem is that TextSearchBoxWelcome on the WelcomeScreen still contains a value when attempting to search again on the BrowseScreenSearch screen, so new search input doesn't work correctly.

 

At the moment I've implemented the following workaround:

 

WelcomeScreen properties:

OnVisible:  UpdateContext({resettext: !resettext}); UpdateContext({resettext: !resettext})

 

TextSearchBoxWelcome properties:

Reset: resettext

HintText: "Search for a room"

 

GoButton properties:

OnSelect: Navigate(BrowseScreenSearch, Fade) && UpdateContext({TextSearchBoxWelcome:""})

 

TextSearchBoxMain properties:

OnSelect: Navigate(BrowseScreenFiltered, Fade)

 

^^^ When the user clicks on the TextSearchBoxMain to perform another search, they are directed to a duplicate Browse Screen (BrowseScreenFiltered) where they can then search the list normally:

 

BrowseScreenFiltered.png

 

The Items property for the BrowseGallery on this screen is set to:

SortByColumns(Filter(MeetingRoomsPowerApp, TextSearchBoxSecondary.Text in Title || TextSearchBoxSecondary.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending))

 

The problem with this workaround is that the search box loses focus, so even though the user has just clicked on the search box, they are navigated to a new screen and have to click on the search box again.

 

Is it possible to either:

 

  1. Use a single BrowseScreen that can filter the gallery using either searchbox, without conflict; OR
  2. Set focus on the TextSearchBoxSecondary when the user navigates to this screen, so they don't have to click into it again in order to type.

 

Thanks in advance!!

1 ACCEPTED SOLUTION

Accepted Solutions

Thanks again for your response @v-micsh-msft Smiley Happy

 

I was able to get this working using the Collect and ClearCollect functions, and by setting a default value for the secondary search box.  I no longer needed the workaround so I deleted the BrowseScreen Filtered screen and updated the other screens as follows:

 

WELCOME SCREEN

 

WelcomeScreen:

OnVisible:  UpdateContext({searchReset:true});UpdateContext({searchReset:false})

 

TextSearchBoxWelcome:

Reset:  searchReset

HintText:  "Search for a room"

OnChange:  false

OnSelect:  false

Default:  ""

 

GoButton OnSelect:

ClearCollect(SearchRoom, TextSearchBoxWelcome.Text); If(Len(TextSearchBoxWelcome.Text) > 0,  Navigate(BrowseScreenSearch, Fade));Collect(MeetingRoomsPowerApp, TextSearchBoxWelcome.Text); If(Len(TextSearchBoxWelcome.Text) > 0,  Navigate(BrowseScreenSearch, Fade))

 

 

BROWSE SCREEN SEARCH

 

TextInputSearchBox properties:

OnChange:  false

OnSelect:

Default:  First(SearchRoom).Value

Reset:  searchReset

HintText:  "Search for a room"

 

SearchButton OnSelect:

If(Len(TextInputSearchBox.Text) > 0, ClearCollect(SearchRoom, TextInputSearchBox.Text), Clear(SearchRoom))

 

Items property for BrowseGallerySearch:

SortByColumns( Filter(MeetingRoomsPowerApp, TextInputSearchBox.Text in Title || TextInputSearchBox.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending))

 

DetailScreenButton OnSelect:

ClearCollect(SearchRoom, ThisItem); Collect(PreviousSearchRoom, SearchRoom);Navigate(DetailScreenSearch, Fade)

 

 

This method uses 2 collections:  SearchRoom and PreviousSearchRoom.  I haven't really used collections before, but I was able to dissect the 'Employee Org' powerapp template to get an understanding of what was required.

 

View solution in original post

3 REPLIES 3
v-micsh-msft
Community Support
Community Support

Hi @starwispy,

 

Option 1 should be possible.

Please consider change the formula in the following format:

SortByColumns(
           Filter(MeetingRoomsPowerApp, 
                   and(TextSearchBoxWelcome.Text in Title || 
                          TextSearchBoxWelcome.Text in Equipment,
TextSearchBox1_1.Text in Title ||
TextSearchBox1_1.Text in Equipment
) ), "Title", If(SortDescending1, Descending, Ascending))

Regards,

Michael

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

Hi Michael,

That's a much cleaner formula, thank you.  Unfortunately without also clearing the value from the WelcomeScreen search box, it only returns results where the item matches both search box values.  I'd like for the search on the second screen to replace the original search, rather than act as a secondary filter.

 

Is there a version of UpdateContext, or a similar parameter, that will work across screens (clearing the search value from the welcome screen search box when a user selects the browse screen search box? 

Thanks again for your response @v-micsh-msft Smiley Happy

 

I was able to get this working using the Collect and ClearCollect functions, and by setting a default value for the secondary search box.  I no longer needed the workaround so I deleted the BrowseScreen Filtered screen and updated the other screens as follows:

 

WELCOME SCREEN

 

WelcomeScreen:

OnVisible:  UpdateContext({searchReset:true});UpdateContext({searchReset:false})

 

TextSearchBoxWelcome:

Reset:  searchReset

HintText:  "Search for a room"

OnChange:  false

OnSelect:  false

Default:  ""

 

GoButton OnSelect:

ClearCollect(SearchRoom, TextSearchBoxWelcome.Text); If(Len(TextSearchBoxWelcome.Text) > 0,  Navigate(BrowseScreenSearch, Fade));Collect(MeetingRoomsPowerApp, TextSearchBoxWelcome.Text); If(Len(TextSearchBoxWelcome.Text) > 0,  Navigate(BrowseScreenSearch, Fade))

 

 

BROWSE SCREEN SEARCH

 

TextInputSearchBox properties:

OnChange:  false

OnSelect:

Default:  First(SearchRoom).Value

Reset:  searchReset

HintText:  "Search for a room"

 

SearchButton OnSelect:

If(Len(TextInputSearchBox.Text) > 0, ClearCollect(SearchRoom, TextInputSearchBox.Text), Clear(SearchRoom))

 

Items property for BrowseGallerySearch:

SortByColumns( Filter(MeetingRoomsPowerApp, TextInputSearchBox.Text in Title || TextInputSearchBox.Text in Equipment), "Title", If(SortDescending1, Descending, Ascending))

 

DetailScreenButton OnSelect:

ClearCollect(SearchRoom, ThisItem); Collect(PreviousSearchRoom, SearchRoom);Navigate(DetailScreenSearch, Fade)

 

 

This method uses 2 collections:  SearchRoom and PreviousSearchRoom.  I haven't really used collections before, but I was able to dissect the 'Employee Org' powerapp template to get an understanding of what was required.

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

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