Convert dropdown to checkbox in PowerApps
Published by Prateek Mangal on
Convert default dropdown to checkbox selection in Power Apps
As we all know, PowerApps is great tool where developer or even a business user can develop an App which is not required any programming knowledge. But when it comes to the customization with PowerApps it is needed a little bit idea to implement a customized solution with same concept of No-code.
As we are familiar with SharePoint and know that multiple checkboxes field in SharePoint is available with classic page experience and little bit got changed in design with modern page experience.
Classic Page Design
We have seen that Choice field with multiple selection is simply like a collection of checkbox where user can select single or multiple checkboxes.
Modern Page Design
Similarly In Modern Page design, user can select single or multiple checkboxes, but it is more like dropdown.
If we are going to edit this form in PowerApps, we will be able to see only a dropdown with multiple selection which is basic control available in PowerApps.
Now here customization of this control begins. Please follow below steps to implement a multi checkbox control:
- Customize default list form with PowerApps using option described as below:
- You will be able to see default multi select drop-down.
- You need to create a collection to work with new and edit form (new list item and existing list item). Write below code to create collection:
ClearCollect(collectionHobbies,AddColumns(Choices([@CustomApprovalProcess].Hobbies),"Checked",If(SharePointForm1.Mode=FormMode.New,false,Not(IsBlank(LookUp(RenameColumns(SharePointIntegration.Selected.Hobbies,"Value","SelectedValue"),SelectedValue=Value))))));Once collection is defined then we need to implement our control. Here we are going to use Gallery control with one checkbox control. For this you need to unlock dropdown card from advance setting
- After defining collection, you need to unlock dropdown card from advance setting.
- Once data card is unlocked then you need to add gallery control in data card and add checkbox to added gallery control. Also, you need to hide your default dropdown control.
- Now you need to modify some properties of this control so it will look like SharePoint control.
Gallery -> Items -> collectionHobbies
Gallery -> WrapCount -> 2 (As per your choice)
Gallery -> Height -> 40 * Round(CountRows(Gallery1.AllItems)/2,0) (here we have 40 as checkbox size not height of checkbox and dividing our total gallery count with 2 as we have set this as WrapCount)
Gallery -> Checkbox -> Text - > ThisItem.Value
Gallery -> Checkbox -> Default - > ThisItem.Checked
Gallery -> Checkbox -> OnSelect -> false - After these settings, out control will look like:
- Now you need to implement update part where collection will be updated with selected or unselected values. For this, you need to bind action on OnCheck and OnUncheck operations of checkbox control.
1. OnCheck
UpdateIf(collectionHobbies, Value=ThisItem.Value, {Checked: true})OnUnCheck
2. OnUncheck
UpdateIf(collectionHobbies, Value=ThisItem.Value, {Checked: false}) - Now you need to bind collection with selected value(Checked) with hidden default dropdown. To verify data, which you have selected, you can unhide hidden dropdown, but need to be hidden before final publishing to SharePoint. To bind selected values, you need to modify below property of dropdow:
DefaultSelectedItems -> Filter (collectionHobbies, Checked)
- One point to be noted here that SharePoint loads PowerApps screen only one time when your SharePoint pages is loaded. As a result, your collection will be bind with values only one time and will not be updated with different list item. To resolve this issue, we need to add one trick with OnNew, OnEdit and OnView operations which will ensure all statements should be executed every time when user clicks on New/Edit/View.
Navigate (FormScreen1)
- To verify this customization, play the app and start selecting some value from checkbox then you will be able to see an update in dropdown. Once verification is completed then you can hide dropdown and publish changes in SharePoint. Now your customized control will be available with SharePoint modern page experience.
4 Comments
Bron Brookes · November 20, 2020 at 5:36 AM
Where do you implement step three? it was not clear if this needs to be in the SharePoint integration mode for on new and on edit or in the control
Prateek Mangal · February 10, 2021 at 8:51 AM
It is implemented on OnVisible of screen. Also, make sure you follow step 10.
Ahmad · February 8, 2021 at 12:06 AM
Hello dear Prateek I am having a problem in the edit form I need to see the pre-selected items from new form in the edit form how can i do that please help using this scenario . I got the items only in the combobox but in the gallery checkboxes no items are selected as in combobox . Please help
Prateek Mangal · February 10, 2021 at 8:48 AM
If you follow step third and sixth, then you can find that I have created one collection for checked items which can be identified using one column “Checked”. After step third in 6th step, we bind collection with check box gallery and set default to ThisItem.Checked.
And point to be remember that collection should be created after loading Form for each item when you open it and same is explained in step 10.