Checkbox Group

lightning:checkboxGroup

A checkbox group that enables selection of single or multiple options. This component requires API version 41.0 and later.

For Aura components only. For LWC development, use lightning-checkbox-group.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:checkboxGroup component represents a checkbox group that enables selection of single or multiple options.

If the required attribute is set to true, at least one checkbox must be selected. When a user interacts with the checkbox group and doesn't make a selection, an error message is displayed. You can provide a custom error message using the messageWhenValueMissing attribute.

If the disabled attribute is set to true, checkbox selections can't be changed.

This component implements styling from Checkbox in the Lightning Design System.

This example creates a checkbox group with two options and option1 is selected by default. At least one checkbox must be selected as the required attribute is true.

You can check which values are selected by using cmp.find("mygroup").get("v.value"). To retrieve the values when a checkbox is selected or deselected, use the onchange event handler and call event.getParam("value").

To create checkboxes, pass in the following properties to the options attribute.

PropertyTypeDescription
labelstringThe text that displays next to a checkbox.
valuestringThe string that's used to identify which checkbox is selected.

Client-side input validation is available for this component. For example, an error message is displayed when the checkbox group is marked required and no option is selected. Note that a disabled checkbox group is always valid.

The validation occurs for the checkbox group, not for an individual checkbox. To override the default message "Complete this field" displayed when a selection on a checkbox group is required and no option is selected, use the messageWhenValueMissing attribute. This message is displayed when you remove focus from the checkbox group.

The validity attribute returns the ValidityState object, with the following supported properties.

  • valid: Returns true if the checkbox group meets all its validation constraints.
  • valueMissing: Returns true if the checkbox group is required but no checkbox is selected.

Other properties such as badInput are not supported.

This example creates a checkbox group that requires a selection and a button that checks validity when clicked.

checkValidity() returns true if at least one checkbox is selected, or false if none is selected. Calling checkValidity() is equivalent to returning validity.valid on the checkbox group.

To programmatically display error messages on invalid fields, use the reportValidity() method.

For custom validity error messages, display the message using setCustomValidity() and reportValidity(). setCustomValidity() overrides the error message you provide using the messageWhenValueMissing attribute. For more information, see the lightning:input documentation.

lightning:checkboxGroup is useful for grouping a set of checkboxes. If you have a single checkbox, use lightning:input type="checkbox" instead.

The checkbox group is nested in a fieldset element that contains a legend element. The legend contains the label value. The fieldset element enables grouping of related checkboxes to facilitate tabbing navigation and speech navigation for accessibility purposes. Similarly, the legend element improves accessibility by enabling a caption to be assigned to the fieldset.