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

Is there a way to reset just the SearchText in a combo box?

I've got a combo box which we're using to select a set of people, but my users are a little bit annoyed at having to clear the search text between selections. Is there a way to reset just the SearchText after selecting a user? I've tried cmb.SearchText="" in the OnSelect action, but that doesn't seem to work at all. 

3 REPLIES 3
Super User
Super User

Re: Is there a way to reset just the SearchText in a combo box?

Have you tried using the combo box's Reset property? This takes a boolean value and can set the combo box to it's default value. One way you could use this would be to set a variable, say ResetComboBox, to false in the OnVisible property of the screen the control is on. Then, in the OnHidden property of the same screen, set the variable to true. Something like this:

 

// In the OnVisible property
UpdateContext({ResetComboBox: false})

// In the OnHidden property
UpdateContext({ResetComboBox: true})

That should reset the combo box to it's defaults when the screen is made hidden and then visible again.

 

This is just one example of how to use the Reset property but another would be to set the ResetComboBox variable using a navigation control or something like that. I'm not sure you would want to do this in the OnSelect property of the combo box without finding some way to set the user selection to a variable first. 

 

Feel free to let me know if that helps or if I can help with crafting the reset scenario. 

MQN
Level: Powered On

Re: Is there a way to reset just the SearchText in a combo box?

So basically, what I'm hoping to do is this:

 

https://imgur.com/V0HF9V4

 

The text typed in persists even after a selection is made, but I would like to clear it out so that if my users wanted to search for, say, "John" afterwards, they wouldn't have to delete the "Mich" first. That's why I tried to clear out SearchText in the OnSelect property. Since there isn't likely to be a screen refresh between resets, I'd like to reset it as soon as they make a selection.

Super User
Super User

Re: Is there a way to reset just the SearchText in a combo box?

Gotcha. So unfortunately I don't think there is a way to clear the search text without resetting the entire combo box, which means that we may have to tweak your scenario a bit to make that happen. And further, resetting the combo box resets everything in the combo box, not just the search text, so doing this from the OnSelect or OnChange of said combo box will clear the selection out as soon as the reset is triggered. 

 

What about adding a button to confirm the selection? This would allow the user to select an item from the combo box, set that selection to a collection, and then reset the combo box. You may have to change some of your app to reference the selected value(s) from the collection, but this would at least give you the behavior you are seeking. 

Here is one way to do that:

// In the OnSelect of a confirmation button
ClearCollect(
        colComboBox1SelectedItems,
        ComboBox1.SelectedItems
);
UpdateContext({ResetComboBox: true});
UpdateContext({ResetComboBox: false}) /* I do this to clear the combo box but then keep the ResetComboBox value primed for the next time it needs to be triggered */

// In the Reset property of the combo box
ResetComboBox

 

The selected value(s) can then be referenced from the colComboBox1SelectedItems collection. You would probably want to add the following to the OnHidden property of the screen, just to keep things clean:

// In the OnHidden property of the screen with the combo box
Clear(colComboBox1SelectedItems)


It may not be much better than clicking the "X" in the text input area of the combo box, but it does keep from needing to clear the search text every time. Let me know what you think!

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,833)