web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Search function only r...
Power Apps
Unanswered

Search function only returns results when input text field is populated

(0) ShareShare
ReportReport
Posted on by 97

I have the following Search function in the item property of my gallery:

 

Search(Lessons,SearchLessonsInput.Text,"LessonKeywords_")))

 

When I publish my app and Power Apps opens the form it displays no records. If I enter a search string (even a space) in the search text input field the records finally display.

 

Can I use some type of nested expression to show all records if the search input field is blank and then execute the search function if the field is populated?

Categories:
I have the same question (0)
  • JRaasumaa Profile Picture
    1,325 on at

    I've got a few search fields to control gallery filters and I use 2 things to make it work.

     

    1st is have a varable in the Input Text Default field to be able to reset to nothing being entered (I like to have hint text in the field as well to allow for some prompting)

     

    In order to reset this I have the OnVisible property or a reset button do an UpdateContext({resetText: " ", resetText: ""}) with the variable resetText in the Default field. This will clear any spaces or entered data out of your search field.

     

    2nd is to have an If statement controlling filtering or searching. Something simply like:

     

    If(SearchInput.Text<>"", Filter or Search etc. etc.

     

    The "false/else" in the statement would be your regular non-filtered collection or data.

     

    Doing both of these allows for a set of data to be shown first, and then upon search text entry the filter/search kicks off and changes the collection or gallery data.

     

     

     

     

  • idcampbell Profile Picture
    97 on at

    Thanks for your help. I've made some progress, but am still struggling with the searching capability after the If statement.

     

    My modified formula now displays all of the records, but when I enter a search string into the input text all the records still display.

     

    If(SearchLessonsInput.Text<>"",Lessons,(Search(Lessons,SearchLessonsInput.Text,"LessonKeywords_")))

     

    Any ideas?

     

    Also, do I have to clear the search field? I do not see an OnVisible property for the text field.

  • Verified answer
    JRaasumaa Profile Picture
    1,325 on at

    You will want to switch the two if true/false locations:

     

    If(SearchLessonsInput.Text<>"",(Search(Lessons,SearchLessonsInput.Text,"LessonKeywords_")),Lessons)


    That way if the .Text has a value it runs your search, and if it is empty then load all of the collection Lessons.

     

    To clear out the SearchLessonsInput you can use the example 1 I previously sent. Put a variable into the SearchLessonsInput  default called resetText.

    Then in your screens OnVisible put in UpdateContext({resetText: " ", resetText: ""})

     

    That will force the text in SearchLessonsInput to be cleared out to nothing everytime you open that screen (on load effectively).

     

    edit: Just a quick note, I also add either an X or refresh button with that same UpdateContext resetting of the variable so the user can clear and refresh the filtered information easier than deleting the contents manually.

     

    You may also want to try: UpdateContext({resetText:" "});UpdateContext({resetText:""}) as the variable reset. I honestly can't remember if that works better than in a single statement.

     

     

  • idcampbell Profile Picture
    97 on at

    The modified search formula did the trick, thanks! The only thing missing is that none of the records in the gallery display until I place my cursor into the Input Text search field. Once I place my cursor into the text box, then all records display and I can subsequently search.

     

    I added the UpdateContext({resetText: " ", resetText: ""}) formula to OnVisible, but had to modify it to UpdateContext({resetText: " }) as Power Apps did not accept the additional variable.

  • JRaasumaa Profile Picture
    1,325 on at

    It might be worth trying to change your Search to a ClearCollection instead and then filtering based on the Search Input you have. That's how I'm driving all of my gallery items by doing a ClearCollection and Filter when that Search Input changes and it works fantastically.

     

    Glad you are making progress!

  • idcampbell Profile Picture
    97 on at

    I accepted the solution as the nested If and Search statements. I am hesitant to use the filter function as the search text input box needs to search against multiple fields (and I hear nesting within nesting a filter statement can get nasty).

     

    Thanks again!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard