Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 1s/L9yRgypCsq7OzO11kAS
Power Apps - Building Power Apps
Answered

combobox force a selection

Like (1) ShareShare
ReportReport
Posted on 19 Jan 2021 15:55:14 by

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

Categories:
  • KetanMehta Profile Picture
    2 on 20 Aug 2022 at 17:35:08
    Re: combobox force a selection

    @joef 

     

    My requirements are same as yours! However, I am not able to understand solution for this! Could you please elaborate on solution!

    My Apologies but I am new to Power App and hence probably not able to follow everything!

     

    Thanks for your help and support!

  • Verified answer
    joef Profile Picture
    on 21 Jan 2021 at 21:13:12
    Re: combobox force a selection

    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

  • JR-BejeweledOne Profile Picture
    5,836 Super User 2025 Season 1 on 20 Jan 2021 at 20:20:53
    Re: combobox force a selection

    While I agree with Randy that not using variables when not needed is a great idea, you may need to in this instance. 

     

    Randy may have a better idea.

  • joef Profile Picture
    on 20 Jan 2021 at 19:46:06
    Re: combobox force a selection

    Thanks again both @RandyHayes  and @JR-BejeweledOne ,

     

    Funny I can't use the IsBlank() in the "OnChange" event but I can in the warning text box.

    The warning pops up, and I can't get rid of the warning without choosing an item, perfect 🙂

     

    But If I delete the empty row from my gallery, the warning stays there, is there a way to reference the visibility?

    I would add it to the delete button to hide the Warning.  

     

    My app has an add button that patches a new row to the list with a blank location for my gallery, the warning pops up (OK)

    You choose an item the warning goes away! (great)

     

    I Patch another new row to my list (warning pops up Great!) , but I decide I didn't want to add the new row, so I delete the row, the Warning is still there until I choose another dropdown from the gallery, or add another row and populate it.

    Same thing happens if I just delete a row from my gallery, until I choose another.

     

    TIA,

    Joe

     

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 20 Jan 2021 at 18:51:23
    Re: combobox force a selection

    @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)

  • JR-BejeweledOne Profile Picture
    5,836 Super User 2025 Season 1 on 20 Jan 2021 at 18:44:24
    Re: combobox force a selection

    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.

     

     

  • joef Profile Picture
    on 20 Jan 2021 at 18:33:45
    Re: combobox force a selection

    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 Profile Picture
    5,836 Super User 2025 Season 1 on 19 Jan 2021 at 16:41:46
    Re: combobox force a selection

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

     

     

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 19 Jan 2021 at 16:40:08
    Re: combobox force a selection

    @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.

  • joef Profile Picture
    on 19 Jan 2021 at 16:39:43
    Re: combobox force a selection

    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...

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,083 Most Valuable Professional

Leaderboard