cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Limit selected items in a field that references a SharePoint list choice field

Hi,

 

In Power Apps, I have five choice options in a field pulled from SharePoint and I only want to allow two to be selected at a time.  How can I accomplish this?

 

Here is the filed I use which displays the five choices:

Choices([@'Form'].Which_x0020_of_x0020_the_x0020_f)

1 ACCEPTED SOLUTION

Accepted Solutions

@cbernier35 

Combo box controls have no mechanism to limit the number of choices.

But I think add an Error Message under the Combobox to remind users to only select two choices at a time if selecting more than 2 choices.

Set ErrorMessage Label Text:

 

If(CountRows(DataCardValue31.SelectedItems)<>2,"You must Only select 2 choices",Parent.Error)

 

Set Submit button DisplayMode:

 

If(CountRows(DataCardValue31.SelectedItems)=2, DisplayMode.Edit, DisplayMode.Disabled)

 

And set Default of box:

 

If(CountRows(DataCardValue31.SelectedItems)=2, CountRows(DataCardValue31.SelectedItems))

 

then if the user selects more than 2 choices, it will show the error message, and the submit button will be disabled, and the Box doesn't show the default value.

Snipaste_2020-02-13_10-29-05.png

Sik

 

 

 

View solution in original post

5 REPLIES 5
Community Support
Community Support

@cbernier35 

 

Do you mean you want the dropdown only list two options?

Please try this:

 

Filter(Choices([@'Form'].Which_x0020_of_x0020_the_x0020_f), Value="Option1" || Value="Option2")

 

Sik

Hi, sort of, I want all five options to show, however I only want the user to be able to select two at a time.  Doesn't matter which two, just has to be two.

How about this, I have a text box where it populates a number when a selection is made, so if I select 2 the number will increment to 2 and so on.  How would I validate the field?  If the count of the file is greater than 2 then block save and show error message.

 

This is the code in the "default" box for the field that counts the number of selections:

CountRows(DataCardValue31.SelectedItems)

@cbernier35 

Combo box controls have no mechanism to limit the number of choices.

But I think add an Error Message under the Combobox to remind users to only select two choices at a time if selecting more than 2 choices.

Set ErrorMessage Label Text:

 

If(CountRows(DataCardValue31.SelectedItems)<>2,"You must Only select 2 choices",Parent.Error)

 

Set Submit button DisplayMode:

 

If(CountRows(DataCardValue31.SelectedItems)=2, DisplayMode.Edit, DisplayMode.Disabled)

 

And set Default of box:

 

If(CountRows(DataCardValue31.SelectedItems)=2, CountRows(DataCardValue31.SelectedItems))

 

then if the user selects more than 2 choices, it will show the error message, and the submit button will be disabled, and the Box doesn't show the default value.

Snipaste_2020-02-13_10-29-05.png

Sik

 

 

 

View solution in original post

The solution works, however this is a SharePoint form so there is not "submit" button.  There is only the save button that is part of the SharePoint site form.  Any way to disable save using the same method outlined?

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (20,277)