Files
2026-08-11 17:40:39 -03:00

52 lines
1.7 KiB
HTML

---
id:
type: 'string'
name:
type: 'string'
default: ''
required:
type: 'bool'
default: false
attributes:
type: 'string'
default: ''
class:
type: 'string'
default: 'form-select'
items:
type: 'array'
---
{% assign base_id = id | append: '_' %}
{% assign name = name | default: id | append: '[]' %}
{% assign attributes = attributes
| append: ' '
| append: 'data-required-checkbox-target="checkbox" data-action="required-checkbox#change"'
%}
{% comment %}
Array parameters do not play well with the check_box helper. According
to the HTML specification unchecked checkboxes submit no value. However
it is often convenient for a checkbox to always submit a value. The
check_box helper fakes this by creating an auxiliary hidden input with
the same name. If the checkbox is unchecked only the hidden input is
submitted and if it is checked then both are submitted but the value
submitted by the checkbox takes precedence.
Source: https://guides.rubyonrails.org/v6.1/form_helpers.html#combining-them
{% endcomment %}
{% render 'forms/hidden.html', name:, id:, value: '' %}
<div data-controller="required-checkbox">
<div style="height: 0px">
{% render 'forms/checkbox.html', name:, id:, value: '', item: '', required:, attributes: 'data-required-checkbox-target="required"' %}
</div>
{% for input_item in items %}
{% capture uuid %}{% uuid %}{% endcapture %}
{% assign value = input_item | try: 'value' | default: input_item %}
{% assign item = input_item | try: 'item' | default: value %}
{% assign id = base_id | append: uuid %}
{% render 'forms/checkbox.html', name:, id:, value:, item:, attributes: %}
{% endfor %}
</div>