I built a Travel Request application in Power Apps a few days ago. Within that application, I have two checkboxes to describe flight ticket types: Economy and Business. I was required to build a logic so the user could select any option from the two checkboxes.
In this article, I will explain how to achieve a single selection from multiple checkbox controls in Power Apps.
Power Apps Uncheck Checkbox When Another is Checked
Here, we will discuss the Power Apps uncheck the checkbox when another is checked with a simple example:
Example-1:
In Power Apps, I have added three Checkbox controls, i.e., [chk_Male, chk_Female, and chk_Others]. The remaining checkbox controls will be unchecked whenever the user selects one checkbox value.
Refer to the below screenshot:
Also, when the user provides the data in the new Power Apps form and clicks the button control, it will be saved or patched on the respective SharePoint Online list [Employee Registration], as shown below.
To achieve this example, follow the steps below.
1. I have a SharePoint Online list named “Employee Registration,” and this list contains the below
Column Name | Data Type |
First Name | It is a single line of text |
Last Name | A single line of text |
Gender | A single line of text |
Designation | A single line of text |
Note:
If you want to patch the Power Apps manual form data into the SharePoint list then, you should add only text fileds as I mentioned-above.
2. Now, on the Power Apps app -> Select the App object and set Its OnStart property to the code below.
OnStart = Set(varMale,true);
Set(varFemale, false);
Set(varOthers, false);
Where,
- Set() = This function is used to set a global variable to the entire app
- varMale, varFemale, varOthers = Variable Names
3. On the Power Apps Screen -> Insert three Text input controls -> insert three Checkbox controls, and set Its Default and UnCheck properties as shown below.
Default = varMale
UnCheck = Set(
varMale, //For chk_Male
true
);
Reset(chk_Female);
Reset(chk_Others)
Default = varFemale
UnCheck = Set(
varMale, //For chk_Female
false
);
Reset(chk_Male);
Reset(chk_Others)
Default = varOthers
UnCheck = Set(
varMale, //For chk_Others
false
);
Reset(chk_Female);
Reset(chk_Male)
Where,
- chk_Male, chk_Female, chk_Others = Power Apps Checkbox Control Names
- Reset() = This function is used to reset a control to its Default property value
4. Finally, insert a Button control and set its OnSelect property to the code below.
OnSelect = Patch(
'Employee Registration',
Defaults('Employee Registration'),
{
Title: TextInput_FirstName.Text,
'Last Name': TextInput_LastName.Text,
Designation: TextInput_Designation.Text,
Gender: If(
chk_Male.Value,
"Male",
chk_Female.Value,
"Female",
chk_Others.Value,
"Others"
)
}
)
Where,
- Patch() = This Patch function allows you to create and modify records in your data source
- ‘Employee Registration’ = SharePoint Online List
- Defaults() = This function uses the Defaults function to pre-populate a data entry form, making filling it easier.
- Title, ‘Last Name’, Designation, Gender = SharePoint List Text Fields
- “Male”, “Female”, “Others” = Checkbox Text Values
5. Once your app is ready, Save, Publish, and Preview the app. When the user provides data in the Power Apps form [Including the checkbox value] and clicks on the button control, it will be saved in the SharePoint Online list like below.
This is how to work with the Power Apps uncheck the checkbox when another is checked.
Example-2:
In Power Apps, there is a Checkbox control inside a Power Apps gallery control. When the user selects any product name from the checkbox control, the remaining checkbox controls will uncheck, as in the screenshot below
To achieve it, follow the below steps.
1. I have a SharePoint list Online named “Product Details.” This list contains the below fields.
2. Next, on the Power Apps screen -> Insert a Blank flexible gallery control and set its Items property as:
Items = 'Product Details'
Where,
- ‘Product Details’ = SharePoint Online List
3. Then, insert a Checkbox control inside the gallery and set its Text property to the code below.
Text = ThisItem.Title
Where,
- Title = SharePoint list text field
4. Whenever we add a checkbox control, we can select multiple checkbox values. However, our requirement is that Power Apps uncheck the checkbox when another is checked, as shown below.
5. To do so, set the Check box’s OnCheck, Default, and DisplayMode properties as shown below.
OnCheck = Set(
varCheck, //OnCheck Property
gal_EmployeeDepartments.Selected.Title
)
Default = varCheck=ThisItem.Title //Default Property
DisplayMode = If(
varCheck = ThisItem.Title, //DisplayMode Property
DisplayMode.View,
DisplayMode.Edit
)
Where,
- varCheck = Power Apps Variable Name
- gal_EmployeeDepartments = Power Apps Gallery Name
6. Save, Publish, and Preview the app. When the user selects any product name from the checkbox control inside the gallery, the remaining checkbox controls automatically uncheck like below.
Example-3: [Achieve Single Selection From Multiple Check Box Controls in Power Apps]
In the example below, you can see that after selecting Economy, if im selecting Business, the Economy option is unselected. The same thing is repeated for the Business check box.
To achieve this, follow the steps below!
1. Provide the formula below in the OnCheck property of the Economy check box control in Power Apps.
UpdateContext({EconomySelected: true});
If(
EconomySelected,
UpdateContext({BusinessSelected: false})
);
Here, EconomySelected and BusinessSelected are Power Apps’ local variables. The above code describes,
- The EconomySelected variable is set as true.
- If the EconomySelected value is true, then the BusinessSelected variable value is updated as false.
2. Provide the variable name below in the Economy check box’s Default property:
EconomySelected
Here, the EconomySelected variable value is true, so this variable value will be changed when we check the business check box.
3. Provide the below formula in the OnCheck property of the Business check box control.
UpdateContext({BusinessSelected: true});
If(
BusinessSelected,
UpdateContext({EconomySelected: false})
);
Like in the above case, it works opposite to the economy check box selection. This means the EconomySelected variable is set to false if the BusinessSelecte variable is true.
4. Provide the variable below in the Business check box’s Default property:
BusinessSelected
This variable value changes based on the selection of the economy checkbox.
5. To reset the checkboxes, provide the formula below in the Reset buttons OnSelect property.
UpdateContext(
{
EconomySelected: false,
BusinessSelected: false
}
);
Basically, with the Reset() function, we’ll reset the Power Apps controls. But here, the checkbox controls contain some default values, so even when we use the reset function, any checkbox is selected. So, we need to update the variables to false.
This way, we can reset the checkboxes which contain default values.
I hope you understand how to uncheck a check box when another check box is checked in Power Apps.
You can adjust the variable names and the number of checkboxes. Even if you have three checkboxes, you follow the above steps, add an extra variable, and update it based on your requirements.
Conclusion
I trust this Power Apps tutorial taught in detail information about the Power Apps check and uncheck the checkbox control.
Here, we learned how to work with three checkbox controls. The remaining checkbox controls will be unchecked when the user selects any checkbox value in a Power Apps canvas app.
Also, we covered that in Power Apps, there is a checkbox control inside the gallery control; whenever the user selects any product name from the checkbox control, the remaining checkbox controls will uncheck.
You may also like:
- Filter Power Apps Line Chart Based On Date Range
- Show Message If Gallery is Empty in Power Apps
- Count Rows in Power Apps Gallery Control
- Power Apps Visible if Checkbox is Checked
- How to Set Power Apps List Box Default Value?
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com