cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
simms7400
Post Prodigy
Post Prodigy

Remove selected item from multi select based on another selection in SAME combobox?

Hi Folks -

I have a multiselect ComboBox that is multiselect.  There are times when the users can select a value called "Not Applicable" and then submit.  However, I need functionality to remove the "Not Applicable" when there is another value selected. Is this possible?

 

For instance, if "Not Applicable" is selected, then "Value2" is select, I need to remove "Not Applicable" from the selection.

 

Thank you!

6 REPLIES 6
mdevaney
Super User
Super User

@simms7400 

In my humble opinion the best way to ensure a valid selection is made would be to prevent the user from making an invalid selection.  For example, suppose you have a collection like this

 

ClearCollect(
    myCollection,
    {Value: "Option 1"},
    {Value: "Option 2"},
    {Value: "Option 3"},
    {Value: "Not Applicable"}
);

 

Now create a new ComboBox with these properties

 

Items: myCollection
DisplayFields: ["Value"]

 

You can prevent the user from selecting Not Applicable when another Option is already selected and vice versa by putting this code in the OnChange property of the ComboBox.

 

 

If(
    "Not Applicable" in ComboBox1.SelectedItems.Value,
    ClearCollect(myCollection,{Value: "Not Applicable"}),
    If(
        IsEmpty(ComboBox1.SelectedItems.Value),
        ClearCollect(
myCollection,
{Value: "Option 1"},
{Value: "Option 2"},
{Value: "Option 3"},
{Value: "Not Applicable"}
), Remove(myCollection,{Value: "Not Applicable"}); ) );

 

Give this method a try for yourself in a Test Application.  I think you'll like it!

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

@mdevaney  

 

Thank you for the solution, this is working as you intended it. However, it's not quite what I need.  For instance, a user can select "Not Applicable" from the list of drop downs based on what data element he or she is creating and submit that.  However, if "Not Applicable" + 1 or mor eother values are also picked, I need to REMOVE Not Applicable from the list of selected items so it's not submitted.

 

Unfortunately, I'm unable to use another field as a control or check to say "If this field is selected, then hide "Not Applicable" from the Combobox...I'm unable to do this.

 

Can this be modified for my need?

Added this to this to the first line and it seems to work!

 

"Not Applicable" in CB_Device_Platform.SelectedItems.Alias && CountRows(CB_Device_Platform.SelectedItems.Alias)>=2

Will test with the users today.  Thank you! I will report back.

v-xida-msft
Community Support
Community Support

Hi @simms7400 ,

I have made a test on my side, please consider take a try with the following workaround:9.JPG

Set the Items property of the ComboBox to following:

["Not Applicable", "Value2", "Value3"]

Set the OnChange property of the ComboBox to following:

ClearCollect(TempCollection, ComboBox1.SelectedItems);
If(
    Last(FirstN(TempCollection, 2)).Value="Value2" && Last(FirstN(TempCollection, 1)).Value="Not Applicable",
    RemoveIf(TempCollection, Value="Not Applicable")
)

Set the DefaultSelectedItems property of ComboBox to following:

ForAll(TempCollection, {Value: Value})

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@mdevaney 

 

I tested the code you gave me (modifying it with my name specifics of course) and its WORKS, however it's just a little bit clunky.  For instance, if user selects "Not Applicable" and then anoher value, the field will get wiped clean but I still need to click on the field, X the "Not Appliable" and then select other value.  My hope was after "Not Applicable" was removed after it met the condition in your code, I wouldn't need to do anything else but select the new values.

 

Thoughts?

 

@v-xida-msft 

 

Hmmm, this loks promising, but my Items property for this box is already set to:

If( DataCardValue133.Selected.Value="Device",
	Filter(Sort(DevicePlatformList,Alias, Ascending),Alias<>"Not Applicable"),
	Sort(DevicePlatformList,Alias, Ascending)
)

And since is a multi-select field, my defaultselecteditems property is set to the following:

Filter(DevicePlatformList, Alias in Split(ThisItem.Device_Platform, ",")).Alias

How would I leverage your soluction with my above things already in place? Thanks!

@simms7400 

PowerApps doesn't let us change the combobox options until a change is completed (your desire) nor does it allow us to manipulate the selection of the combobox once made.  I'm afraid all you can do here is give the user some visual cues (highlight the combo border red) or show an error when they select both at once.  You can also write some form validation code to prevent submission.  Of course, these are just general tips.  Hopefully I have answered you question in an easy to understand way.  Unfortunately, I do not see a really good workaround here.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,486)