Checkbox

Components > Editing Data > Checkbox
Use this component to...
Prompt the user for one or more true/false values

Overview

Use the checkbox component to prompt the user for one or more Boolean (true/false) values.

In Responsive UI, we primarilay use checkboxes for editing Boolean fields in a form, where the form is posted with a Save button. The user typically must take a separate action — i.e. pressing the Save button — for the checkbox state to take effect in the system.

Single Checkbox for a Form Field

When you have a single checkbox for a field in a form, place the field label in the left column and the checkbox input in the right column. This keeps all field labels on the left and all field value editors on the right, a standard previously established by the UI Committee. The checkbox displays without a label directly to the right of it since its field label is already displayed in the left column.

A field that displays a single checkbox, with the field label on the left and the checkbox on the right
A field that displays a single checkbox, with the field label on the left and the checkbox on the right

Multiple Checkboxes for a Form Field

A field that allows the user to select multiple options may display multiple checkboxes in the field value column on the right. The field label displays in the left column, with the checkboxes displaying in the column on the right. In addition, each checkbox displays a separate label for that individual option to the right of the checkbox. ÇThis is the only time a checkbox displays a label to its immediate right in Responsive UI.

A field that displays multiple checkboxes, with the field label on the left, the checkboxes on the right, and a sub-label next to each checkbox
A field that displays multiple checkboxes, with the field label on the left, the checkboxes on the right, and a sub-label next to each checkbox

Development

Web component development

Component reference

p-checkbox
p-checkbox
Module: CheckboxModule - Package: primeng
⚠️ This component requires the use of Angular and will not work in non-Angular applications.

Changes a Boolean value in a form that requires a separate action like a Save button to take effect

View the p-checkbox reference doc

If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.

Implementation

Begin by importing the CheckboxModule module into your application.

Import the module
// import into app.module
import { CheckboxModule } from 'primeng/checkbox';

@NgModule({
    imports: [
        ...
        CheckboxModule,
        ...
    ]
})

export class AppModule(){}

Single Checkbox Example

The single checkbox approach is used to set a true/false value for an individual property.

Define a field for the boolean value in the controller, then add a p-checkbox instance for the field in the HTML. Bind the formControl property to the appropriate field in the form and set the binary property to a value of true.

You must set the binary property to a value of true for the checkbox to work properly as a single value toggle.
Single selection checkbox HTML
<p-checkbox [formControl]="activeCustomer" [binary]="true"></p-checkbox>

Multiple Checkbox Example

The multiple checkbox approach is used to select one or more options from a list.

Import SelectItem from the PrimeNG API. Set up data for the checkbox options in the component or within a service.

Setting up the checkbox options
import { SelectItem } from 'primeng/api';

...

const retirementAccountTypeList: SelectItem[] =
[
    { label: 'Money Market', value: 'Money Market' },
    { label: 'CD', value: 'CD' },
    { label: 'IRA', value: 'IRA' }
];

Add a p-checkbox instance to the HTML, iterating over the list of options. Specify the formControl for the form field, and a value and label for each checkbox.

Multiple selection checkbox HTML
<p-checkbox *ngFor="let account of retirementAccountTypeList" name="groupname"
    value="{{account.value}}" label="{{account.label}}" [formControl]="retirementAccountTypes">
</p-checkbox>

Angular component development

Component reference

p-checkbox
p-checkbox
Module: CheckboxModule - Package: primeng

Changes a Boolean value in a form that requires a separate action like a Save button to take effect

View the p-checkbox reference doc

If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.

Implementation

Begin by importing the CheckboxModule module into your application.

Import the module
// import into app.module
import { CheckboxModule } from 'primeng/checkbox';

@NgModule({
    imports: [
        ...
        CheckboxModule,
        ...
    ]
})

export class AppModule(){}

Single Checkbox Example

The single checkbox approach is used to set a true/false value for an individual property.

Define a field for the boolean value in the controller, then add a p-checkbox instance for the field in the HTML. Bind the formControl property to the appropriate field in the form and set the binary property to a value of true.

You must set the binary property to a value of true for the checkbox to work properly as a single value toggle.
Single selection checkbox HTML
<p-checkbox [formControl]="activeCustomer" [binary]="true"></p-checkbox>

Multiple Checkbox Example

The multiple checkbox approach is used to select one or more options from a list.

Import SelectItem from the PrimeNG API. Set up data for the checkbox options in the component or within a service.

Setting up the checkbox options
import { SelectItem } from 'primeng/api';

...

const retirementAccountTypeList: SelectItem[] =
[
    { label: 'Money Market', value: 'Money Market' },
    { label: 'CD', value: 'CD' },
    { label: 'IRA', value: 'IRA' }
];

Add a p-checkbox instance to the HTML, iterating over the list of options. Specify the formControl for the form field, and a value and label for each checkbox.

Multiple selection checkbox HTML
<p-checkbox *ngFor="let account of retirementAccountTypeList" name="groupname"
    value="{{account.value}}" label="{{account.label}}" [formControl]="retirementAccountTypes">
</p-checkbox>

Design

Figma design

Figma design info
You can find this component in the Components - Forms page in the Figma UI Kit.
Dev Component Design Component Name
Checkbox RUI / Forms / Checkbox

Adobe XD design

Adobe XD design info
You can find this component in these artboards in the Adobe XD design samples:
  • Sample App - Editing Form Data
Dev Component Design Component Name
Checkbox - checked JHA / Forms / Checkbox / Checked
Checkbox - unchecked JHA / Forms / Checkbox / Unchecked

Support options
Have questions on this topic?
Join the Responsive UI team in Microsoft Teams to connect with the community.
See something in this page that needs to change?
Send us feedback on this page.
Last updated Wed Mar 29 2023