x
1
2
3
4
<form action="#" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="az_QukMv1wBRo1TKzqpJY3tphW2rYhm5lPhYC6ddy1NGrPyIgTUneVvf1_0Mm2nyW_D-05ZU5i7aHRAdOZjkVQ" autocomplete="off" /><label class="rpf-input-checkbox"><input type="hidden" value="0" name="likes_cheese"><input id="likes_cheese" name="likes_cheese" type="checkbox" value="1"> Do you like <strong>cheese</strong>?</label></form>1
2
3
4
5
<%= form_with url: '#', builder: DesignSystem::FormBuilder do |f| %> <%= f.rpf_checkbox_input :likes_cheese, checked:, modifiers:, error:, **attrs do %> Do you like <strong>cheese</strong>? <% end %><% end %>Checkbox Input Component (without model)
rpf_checkbox_input(:name, label: nil, error: nil, checked_value: 1, unchecked_value: 0, include_hidden: false, modifiers: [], **attrs)This is very similar to the checkbox input component with a
model, but instead the first argument is used as the name
attribute.
<%= form_with url: '#', builder: DesignSystem::FormBuilder do |f| %> <%= f.rpf_checkbox_input :accepts_terms, label: 'I accept the terms', checked: true, modifiers:, **attrs %><% end %>produces:
<!-- form opening tag goes here ---><label class="rpf-input-checkbox"> <input name="accepts_terms" type="hidden" value="0> <input id="accepts_terms" name="accepts_terms" type="checkbox" value="1" checked> I accept the terms.</label>By default the hidden input is set for the unchecked value, so if the checkbox is unchecked the value will be sent, which is what Rails expects.
Arguments
name- The name in the checkbox inputlabel:- The text to display next to the checkboxchecked_value:- Set the checked value -- defaults to1unchecked_value:- Set the unchecked value (ifinclude_hiddenis also set) -- defaults to0include_hidden:- Include the magic extra hidden field, defaults totrueerror:- Any error message to show under the checkboxmodifiers:- Additional classes to apply to the checkbox, e.g.:disabledor:'full-width'
It also accepts all the usual HTML attributes for a checkbox input, e.g. id, class, data- etc.
| Param | Description | Input |
|---|---|---|
|
— |
|
|
|
— |
|
|
|
— |
|