Provides a checkbox group to be used within forms. It yields CheckboxFields back to the consumer so they can render as many checkboxes as needed with built-in state tracking for the selected values.
CheckboxField
: An underlying CheckboxField component. All arguments and attributes of CheckboxField can be supplied (e.g.,@isDisabled
,@hint
, etc.). To give each option a unique value, use the@value
argument.
Required.
Use either the @label
component argument or the :label
named block.
Provide a string to the @label
component argument or content to the :label
named block to render into the legend of the fieldset.
Optional.
Use either the @hint
component argument or the :hint
named block.
Provide a string to the @hint
component argument or content to :hint
named block to render into the Hint section.
Optional. Provide a string to @error
to render the text into the Error section of the fieldset.
To tie into the input event when a checkbox is clicked, provide @onChange
. @onChange
will return two arguments:
- an array containing the selected values
- the raw event object
A @value
argument to the CheckboxGroupField is used to determine which of the checkboxes is currently selected. It does so by comparing @value
provided to the CheckboxGroupField to each @value
of the checkbox. When an @onChange
event occurs, it's most common to update the @value
argument to the newly selected values as shown in the example below.
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class extends Component {
@tracked groupValue = [];
@action
updateValue(value) {
this.groupValue = value;
}
}
To disable the fieldset and all child checkboxes, set the @isDisabled
argument directly on the checkbox group field.
To disable individual checkbox fields, set the @isDisabled
argument directly on the checkbox field.
Consumers have direct access to the underlying checkbox element, so all attributes are supported. Modifiers can also be added directly to individual radio fields.