Checkboxes
Checkboxes
lets you create a group of checkboxes.
-->
Checkboxes
lets you create a group of checkboxes.
Just pass an array of strings into checkboxes
and Checkboxes
takes care of the rest for you.
Checkboxes
wraps checkboxes in a <fieldset>
element since theyβre related. You can also provide an optional label with legend
.
If you like to use custom labels for each checkbox, just pass an array of objects into the checkboxes
property instead.
Checkboxes
give you a convenient way to make everything checked
, disabled
, or readonly
. Just use the relevant properties to make it happen.
Just set checked
, disabled
, or readonly
to true
for each checkbox.
A list of checkboxes sometimes contain an Others
field that lets a user type into. You can create this simply by adding hasInput
to the checkbox object.
Checkboxes
create multiple checkboxes that are wrapped in a <fieldset>
. You can give the group an optional label with legend
.
Like Checkbox
, label
is optional. If you donβt provide a label, Checkboxes
will create a labels for each checkboxes by converting name
to Title Case.
For convenience, you can also pass an array of strings to checkboxes
. In this case, each value will be set as the name
of the checkbox.
If you want everything to be checked, set checked
on the Checkboxes
component.
If you want a single checkbox to be checked, set checked:true
on that checkbox instead.
If you want all checkboxes to be disabled, use the disabled
property on Checkboxes
. Disabled checkboxes will not send data when submitted (even if the checkbox is checked).
If you want to disable a single checkbox, add the disabled
property to that checkbox instead.
If you want all checkboxes to be read-only, use the readonly
property on Checkboxes
. Use this over disabled
if you want to send the checkbox state and value on form submission.
off
when unchecked and on
when checked.value
is provided, value
will be the provided value when checked.Native checkboxes donβt have the readonly
attribute. To simulate readonly
,
Checkbox
creates a hidden input with the same name. See
Checkbox for the HTML output.
If you want to make a single checkbox read-only, add the readonly
property to that checkbox instead.
You can make checkboxes always send their values (even when unchecked) on form submission by setting alwaysSend
.
This creates an additional input for every checkbox (like readonly
) without disabling them.
If you want to make a single checkbox read-only, add the alwaysSend
property to that checkbox instead.
You can add a TextInput
that shows up when a checked is checked by setting the hasInput
property.
Regardless whether this checkbox is checked, it will send TextInput
βs value (which defaults to an empty string) to the server when the form is submitted.
This text input is created by setting name
to the same value as the
checkbox
.
All other properties for each checkboxes
item will be passed into their respective Checkbox
component.
The contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can get the <fieldset>
element with the ref
property.
You can know the state of the checkboxes by binding to the checkboxes
.
{
data: [
{
0: "a",
1: "p",
2: "p",
3: "l",
4: "e"
},
{
0: "b",
1: "a",
2: "n",
3: "a",
4: "n",
5: "a"
},
{
0: "c",
1: "a",
2: "r",
3: "r",
4: "o",
5: "t"
}
]
}
Only the change
event is supported on Checkboxes
right now. You can listen to the event like this:
We only support the change
event because Svelte 4 doesnβt have automatic
event-forwarding capability. All events will be forwarded automatically when
we migrate to Svelte 5.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Checkboxes
create multiple checkboxes that are wrapped in a <fieldset>
. You can give the group an optional label with legend
.
Like Checkbox
, label
is optional. If you donβt provide a label, Checkboxes
will create a labels for each checkboxes by converting name
to Title Case.
For convenience, you can also pass an array of strings to checkboxes
. In this case, each value will be set as the name
of the checkbox.
If you want everything to be checked, set checked
on the Checkboxes
component.
If you want a single checkbox to be checked, set checked:true
on that checkbox instead.
If you want all checkboxes to be disabled, use the disabled
property on Checkboxes
. Disabled checkboxes will not send data when submitted (even if the checkbox is checked).
If you want to disable a single checkbox, add the disabled
property to that checkbox instead.
If you want all checkboxes to be read-only, use the readonly
property on Checkboxes
. Use this over disabled
if you want to send the checkbox state and value on form submission.
off
when unchecked and on
when checked.value
is provided, value
will be the provided value when checked.Native checkboxes donβt have the readonly
attribute. To simulate readonly
,
Checkbox
creates a hidden input with the same name. See
Checkbox for the HTML output.
If you want to make a single checkbox read-only, add the readonly
property to that checkbox instead.
You can make checkboxes always send their values (even when unchecked) on form submission by setting alwaysSend
.
This creates an additional input for every checkbox (like readonly
) without disabling them.
If you want to make a single checkbox read-only, add the alwaysSend
property to that checkbox instead.
You can add a TextInput
that shows up when a checked is checked by setting the hasInput
property.
Regardless whether this checkbox is checked, it will send TextInput
βs value (which defaults to an empty string) to the server when the form is submitted.
This text input is created by setting name
to the same value as the
checkbox
.
All other properties for each checkboxes
item will be passed into their respective Checkbox
component.
The contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can get the <fieldset>
element with the ref
property.
You can know the state of the checkboxes by binding to the checkboxes
.
{
data: [
{
0: "a",
1: "p",
2: "p",
3: "l",
4: "e"
},
{
0: "b",
1: "a",
2: "n",
3: "a",
4: "n",
5: "a"
},
{
0: "c",
1: "a",
2: "r",
3: "r",
4: "o",
5: "t"
}
]
}
Only the change
event is supported on Checkboxes
right now. You can listen to the event like this:
We only support the change
event because Svelte 4 doesnβt have automatic
event-forwarding capability. All events will be forwarded automatically when
we migrate to Svelte 5.
You can import the basic styles for Checkboxes
through Splendid Styles.
If you wish to include only the necessary styles in your project, you can import the following files:
Checkboxes
produces the following HTML:
Please see Checkbox
for the HTML produced by each Checkbox
.
The following classes are used by Checkboxes
:
Class | Description |
---|---|
Fieldset | Styles the <fieldset> |
Legend | Styles the legend |
Checkboxes | Styles the checkbox container |
The following properties can be used to add classes to Checkboxes
.
Property | Description |
---|---|
class | Add classes to Checkboxes |
legendClass | Add classes to the legend |
checkboxesClass | Add classes to the checkbox container |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
You can import the basic styles for Checkboxes
through Splendid Styles.
If you wish to include only the necessary styles in your project, you can import the following files:
Checkboxes
produces the following HTML:
Please see Checkbox
for the HTML produced by each Checkbox
.
The following classes are used by Checkboxes
:
Class | Description |
---|---|
Fieldset | Styles the <fieldset> |
Legend | Styles the legend |
Checkboxes | Styles the checkbox container |
The following properties can be used to add classes to Checkboxes
.
Property | Description |
---|---|
class | Add classes to Checkboxes |
legendClass | Add classes to the legend |
checkboxesClass | Add classes to the checkbox container |
Use these properties to customize Checkboxes
.
Property | Type | Description |
---|---|---|
legend | string | Legend for the group of checkboxes |
checkboxes | array | Checkbox items. See Checkboxes |
checked | boolean | Adds the checked state to all checkboxes when present. |
disabled | boolean | Adds the disabled state to all checkboxes when present. |
readonly | boolean | Adds the readonly state to all checkboxes when present. |
ref | object | Reference for the <fieldset> element |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Use these properties to customize Checkboxes
.
Property | Type | Description |
---|---|---|
legend | string | Legend for the group of checkboxes |
checkboxes | array | Checkbox items. See Checkboxes |
checked | boolean | Adds the checked state to all checkboxes when present. |
disabled | boolean | Adds the disabled state to all checkboxes when present. |
readonly | boolean | Adds the readonly state to all checkboxes when present. |
ref | object | Reference for the <fieldset> element |