Blog
Forms - How to select-all / unselect-all checkbox or toggle controls on a form
April 13. 2021
When building data entry screens, we can simplify data entry by adding a feature to select all, or to unselect all true/false values on a form. This post walks through how to build this feature.
A common requirement is to simplify data entry by providing a single select all/unselect all control.
Adding the 'select all' feature to the edit form
Running the screen
At this stage, our form is complete. When we run the app, the 'select all' toggle control behaves as expected, as shown in the screenshot beneath.
To demonstrate, we'll take the example of an app that's designed for letting agents. The letting process requires an agent to complete a checklist of necessary checks on a property. The screenshot beneath shows an underlying SQL Server table that supports this feature. The value 0 in the checklist fields represent false, whereas 1 represent true.
Adding the 'select all' feature to the edit form
To build this feature, we'll begin with an 'auto generated' app that's based on this table. The first step is to add a 'select all' toggle control to the edit screen. We then set the OnChange property of this control to the following formula:
UpdateContext({locSelectAll:If(Self.Value, "t", "f")});
UpdateContext({locResetToggle:true});
UpdateContext({locResetToggle:false});
This formula sets the value of two variables - locSelectAll and locResetToggle
Next, we set the OnVisible property of the screen to the following formula:- locSelectAll - this variable controls whether to set all other toggle controls on the screen to 'true'. We define this as a string value, which will be empty when the screen loads.
- locResetToggle - this variable triggers a reset of the target toggle controls.
UpdateContext({locSelectAll:""});
Reset(tglSelectAll)
This formula sets the default value of the 'select all' toggle control to off, and configures the form to show the existing values for the target toggle controls when the screen loads.
For each toggle control that we want to respond to the 'select all' toggle control, we unlock the containing card and set the Default property to the following formula:
Switch(locSelectAll, "t", true, "f", false, Parent.Default)
We also set the Reset property of the toggle controls to the following formula:
locResetToggle
Running the screen
At this stage, our form is complete. When we run the app, the 'select all' toggle control behaves as expected, as shown in the screenshot beneath.Conclusion
We can simplify data entry by providing a feature to select or to unselect all true/false values on a form. This post walked through the process to build this feature.
- Categories:
- forms
Related posts
- Forms - How to set the value of a field to todays date for new records only
- Apps - How to create an app from a hand drawn image
- Forms - How to highlight user modified field values on a form
- Forms - How to append text to field in a data source
- Forms - How to calculate values (eg sums and products) and store the results in SharePoint or other datasource
- SharePoint - How to programmatically set and clear single select choice items in a combo box on a form
- SharePoint - How to clear datetime fields/set an empty datetime value on a form
- Forms - How to convert a display form to an edit form
- Forms - How to copy/save an existing record on a form as a new record
- Forms - How to show Office 365 user profile details on a form
- Forms - How to hide fields that are blank, or have not been completed
- Forms - How to set the data source of a form to a collection
- Forms - The best practice for setting the data item on a form
- Controls - How to set default control and form values
- Forms - How to conditionally make form fields mandatory