cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
joef
Continued Contributor
Continued Contributor

combobox force a selection

Hi All,

Is there a way to make sure a valid selection is chosen in a combo box? 

Here is my situation... 

I added a combo box to my gallery, set my choices() and all is working wonderfully, until I let a user try it 🙂

 

When you click the arrow in the combo box I get my choices, if I start typing "001" the only value with "001-EPF" shows up below where I am typing, if you click away thinking the value is in the dropdown, you only get "001" not the full value "001-EPF".

When I patch the value 001 is not saved since it is not a valid choice, and brings back a blank line.  

LocationCombo.jpgLocationComboNotset.jpg

Is there a way to force the full value? 

When there are multiple items you need to make a choice, but when there is only one, I need it to populate fully.

 

TIA,

Joe

1 ACCEPTED SOLUTION

Accepted Solutions
joef
Continued Contributor
Continued Contributor

Hi @JR-BejeweledOne , @RandyHayes ,

I used a combo of both.  I check for empty and on select of the ComboBox, I Set a Var to true. (OnChange I set it back.  Since in my world OnChange only happens when an item is selected this works perfectly :))..

The warning visibility is only when  both are true. 

 

Thanks again both!!!

Joe

View solution in original post

12 REPLIES 12
JR-BejeweledOne
Super User
Super User

This may help you.

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/PowerApps-ComboBox-with-always-one-Selection...



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
joef
Continued Contributor
Continued Contributor

The issue is that when they click the arrow, the default will be removed and if they click away, they will get the 001.

If 001 is in the box, the default is removed, and 001 is there to be saved

Too bad it loads what you start typing, it should stay blank until you choose something.

Try this.

 

In the OnChange property of your combobox, set a formula like this:

 

If(IsBlank(ComboBoxX.SelectedItems), Set(varSelected, false), true)

 

Then have a warning label to become visible if varSelected is true



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
joef
Continued Contributor
Continued Contributor

The issue is that when you start to type the characters are entered into the box, so when you click away, there is a value in the box.  That was my first thought...

RandyHayes
Super User III
Super User III

@joef 

As you have noticed, the selection must be made after typing in the search.  

There is no way to force the combobox to do what you want...HOWEVER, there is a work around!

 

Place a toggle control (let's call it tglOneItem) on your screen and set its Visible property to : false

Set the Default property of tglOneItem to : 

    CountRows(Search(yourComboboxItems, yourComboboxName.SearchText, "yourSearchColumn")) =1

 

Set the OnCheck action to:

    UpdateContext({lclSel: First(Search(yourComboboxItems, yourComboboxName.SearchText, "yourSearchColumn"))}) 

 

Set the DefaultSelectedItems property of your combobox to: lclSel

 

This will give you what you want.  Note: you'll want to UpdateContext({lclSel:Blank()}) somewhere like when the screen is visible to clear that selection - don't try to put it in the OnUncheck action of the toggle as that toggle fires very quickly from checked to unchecked and will clear what you just set.

 

Notice in the below animation, I type "Item 2" and nothing else is clicked or pressed...the combobox will automatically select the One item that is based on that search.

joef.gif

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

I tested this before replying.  It works very well.    Typing into the box isn't the same as actually selecting an item.

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
joef
Continued Contributor
Continued Contributor

Hi @JR-BejeweledOne ,

Typing into the combo box without choosing an item does not fire off the "OnChange" event.  

I placed your code into the OnChange, if I type 00 then click on the next column, nothing happens.

If I choose an item my Var goes to true and my popup shows up.

 

I wanted to go with @RandyHayes  solution, but a bad value is just as bad as an empty value.

I can't allow them to save the item unless there is a value in the combobox....

 

I can't be the only one with this issue... (or am I?)

JR-BejeweledOne
Super User
Super User

Did you try my suggestion?   Again I tested it and you are going to have to build some logic that will prevent them from submitting if there is no value.

 

In the OnChange property of your combobox, set a formula like this:

 

If(IsBlank(ComboBoxX.SelectedItems), Set(varSelected, false), true)

 

Then have a warning label to become visible if varSelected is true, you can also set other controls display mode to view as long as the variable is false which will prevent them from continuing until they select an item.  

 

Your warning can tell them they need to select an item in the box before they can proceed.

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
RandyHayes
Super User III
Super User III

@JR-BejeweledOne 

What I provided should give you what you need for automatically selecting an item if the search returns only one item.

What you are referring to is validation of the control.  In which case you need to simply validate that the control has a selected item prior to allowing to submit.

Why set a variable?? Avoid the variable!!  Simply reference the control in your submit - CountRows(ComboBoxX.SelectedItems)=0 means there is nothing selected - this applies to multi-select.  For single select combos, you can simply validate with IsBlank(ComboBoxX.Selected.xxxxx) where xxxxx is a column in your items records.

 

So, for your warning label, just set the visible to: IsBlank(ComboBoxX.Selected.xxxx)

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (27,216)