Checkbox is used for a list of selections that are meant to have one or more options checked.
When using a custom checkbox wrapped in the Checkbox kit, hidden inputs are not automatically included and cannot be prop enabled. Manually add a hidden input before the checkbox if necessary to submit a value when the checkbox is unchecked (as is standard in Rails forms).
If you want to use indeterminate, "check/uncheck all" checkboxes, add indeterminate_main: true and an id to the main checkbox. Then, add an indeterminate_parent prop with the main checkbox's id to the children checkboxes.
If you want to customize the main checkbox labels, set an array indeterminate_main_labels with "Check All" and "Uncheck All" labels.
<% checkboxes = [ { name: 'Coffee', id: 'coffee', checked: false }, { name: 'Ice Cream', id: 'ice-cream', checked: false }, { name: 'Chocolate', id: 'chocolate', checked: true } ] %> <%= pb_rails("table", props: { container: false, size: "md" }) do %> <thead> <tr> <th> <%= pb_rails("checkbox", props: { value: "checkbox-value", name: "main-checkbox", indeterminate_main: true, indeterminate_main_labels: ["Check All Ice Cream", "Uncheck All Ice Cream"], id: "indeterminate-checkbox" }) %> </th> </tr> </thead> <tbody> <% checkboxes.each do |checkbox| %> <tr> <td> <%= pb_rails("checkbox", props: { checked: checkbox[:checked], text: checkbox[:name], value: checkbox[:id], name: "#{checkbox[:id]}-indeterminate-checkbox", id: "#{checkbox[:id]}-indeterminate-checkbox", indeterminate_parent: "indeterminate-checkbox", }) %> </td> </tr> <% end %> </tbody> <% end %>
<%= pb_rails("flex", props: {orientation: "column"}) do %> <%= pb_rails("flex/flex_item") do %> <%= pb_rails("checkbox" , props: { input_options: { tabindex: 0 }, margin_bottom: "xs", text: "Disabled unchecked", value: "checkbox-value", disabled: true, name: "checkbox-name" }) %> <% end %> <%= pb_rails("flex/flex_item") do %> <%= pb_rails("checkbox" , props: { input_options: { tabindex: 0 }, text: "Disabled checked", value: "checkbox-value", disabled: true, checked: true, name: "checkbox-name" }) %> <% end %> <% end %>
The way to access hidden inputs for form submission depends on which version of the kit being used within the form context.
If using the Rails Checkbox version of the kit, set hidden_input: true. Inspect Checkbox #1 in the example above to see the hidden input in the DOM.
If using the Form Builder version of the kit (reference the Form kit page for more on these), the hidden input will appear if the input has a set unchecked_value. Inspect Checkbox #2 in the example above (and the two checkbox examples on the Form kit page) to see the hidden input in the DOM. See the Rails check_box FormHelper docs for more.
<%= pb_form_with(scope: :example, url: "", method: :get) do |form| %> <%=pb_rails("flex", props: { gap: "sm", orientation: "column"}) do %> <%= pb_rails("checkbox" , props: { text: "1. pb_rails(\"checkbox\") Checkbox from kit", value: "checkbox-value", name: "checkbox-name", hidden_input: true }) %> <%= form.check_box :example_checkbox, data: { field1: "value1", field2: "value2" }, props: { text: "2. form.check_box Checkbox from Form Builder" }, unchecked_value: "no", id: "checkbox-id", name: "checkbox-name", class: "checkbox-class" %> <%= form.actions do |action| %> <%= action.button props: { type: "submit", text: "Submit", variant: "primary" } %> <% end %> <% end %> <% end %>
| Props | Type | Values |
|---|---|---|
align_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_items |
enum | responsive
|
start
end
center
|
border_radius |
enum
|
none
xs
sm
md
lg
xl
rounded
|
cursor |
enum
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
|
dark |
boolean
|
true
false
|
flex |
enum | responsive
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_direction |
enum | responsive
|
row
column
rowReverse
columnReverse
|
flex_wrap |
enum | responsive
|
wrap
nowrap
wrapReverse
|
justify_content |
enum | responsive
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
line_height |
enum
|
loosest
looser
loose
normal
tight
tighter
tightest
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
width |
string
|
|
min_width |
string
|
|
max_width |
string
|
|
gap |
string | responsive
|
|
column_gap |
string | responsive
|
|
row_gap |
string | responsive
|
|
number_spacing |
enum
|
tabular
|
order |
enum | responsive
|
none
first
1
2
3
4
5
6
7
8
9
10
11
12
|
overflow_x |
enum
|
scroll
visible
hidden
auto
|
overflow_y |
enum
|
scroll
visible
hidden
auto
|
overflow |
enum
|
scroll
visible
hidden
auto
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
position |
enum
|
relative
absolute
fixed
sticky
static
|
shadow |
enum
|
none
deep
deeper
deepest
|
text_align |
enum | responsive
|
start
end
left
right
center
justify
justifyAll
matchParent
|
truncate |
enum
|
none
1
2
3
4
5
|
vertical_align |
enum | responsive
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
z_index |
enum | responsive
|
1
2
3
4
5
6
7
8
9
10
max
|
top |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
inset |
boolean
|
true
false
|
right |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
bottom |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
left |
enum | object
|
xxs
xs
sm
md
lg
xl
xxl
|
height |
string
|
|
max_height |
string
|
|
min_height |
string
|
|
hover |
object
|
|
group_hover |
boolean
|
true
false
|
| Props | Type | Values | Default |
|---|---|---|---|
checked |
boolean
|
true
false
|
false
|
disabled |
boolean
|
true
false
|
false
|
error |
boolean
|
true
false
|
false
|
indeterminate |
boolean
|
true
false
|
|
name |
string
|
||
on_change |
reactnode
|
||
required_indicator |
boolean
|
true
false
|
false
|
tab_index |
number
|
||
text |
string
|
||
value |
string
|
||
indeterminate_main |
boolean
|
true
false
|
false
|
indeterminate_main_labels |
array
|
||
indeterminate_parent |
string
|
||
input_options |
string
|
||
required |
boolean
|
true
false
|
false
|
form_spacing |
boolean
|
true
false
|
false
|
hidden_input |
boolean
|
true
false
|
false
|
hidden_value |
string
|