cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
starwispy
Level: Powered On

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
starwispy
Level: Powered On

Re: Help please! Reset search and retain focus

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.

 

3 REPLIES 3
Community Support Team
Community Support Team

Re: Help please! Reset search and retain focus

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.
Highlighted
starwispy
Level: Powered On

Re: Help please! Reset search and retain focus

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? 

starwispy
Level: Powered On

Re: Help please! Reset search and retain focus

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.

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 41 members 4,991 guests
Please welcome our newest community members: