Previews

No matching results.

x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<form action="/" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="2Hv6abh-dxVAdEulfSN_jCiAWOiWjJLyAXjjiYmbdeffUfadn8WOSGy6AME0ifKAFHHZeO7ZNC8L6zgMQkoFcw" autocomplete="off" />
<fieldset x-data="{
uncheckMatching(selector) {
this.$root.querySelectorAll(selector).forEach((cb) => {
if (cb.checked) {
cb.checked = false;
cb.dispatchEvent(new Event('change', { bubbles: true }));
}
});
},
onOptionChange(event) {
if (event.target.matches('input[type=checkbox]') && event.target.checked) {
this.uncheckMatching('[data-exclusive-checkbox-group=exclusive] input[type=checkbox]');
}
},
onExclusiveChange(event) {
if (event.target.matches('input[type=checkbox]') && event.target.checked) {
this.uncheckMatching('[data-exclusive-checkbox-group=options] input[type=checkbox]');
}
},
handleItemClick(event) {
if (event.target.closest('input, label, button, a, [role=button], [data-no-toggle]')) return;
const item = Array.from(event.currentTarget.children).find((child) => child.contains(event.target));
if (!item) return;
const checkbox = item.querySelector('input[type=checkbox]');
if (!checkbox || checkbox.disabled) return;
checkbox.click();
}
}" class="fieldset-group cfa-stack-xl">
<legend class="sr-only">Which of these apply to you?</legend>
<div data-exclusive-checkbox-group="options" class="cfa-stack-xl [&>*]:cursor-pointer" @change="onOptionChange($event)" @click="handleItemClick($event)">
<div class="cfa-card bg-white border border-border-secondary rounded-lg p-cfa-lg">
<div class="cfa-stack-sm">
<div class="flex items-center gap-cfa-sm">
<span class="cfa-checkbox-wrap relative inline-flex h-6 w-6"><input name="form_component_preview_test_model[option_one]" type="hidden" value="" autocomplete="off" /><input class="cfa-checkbox h-6 w-6 rounded border checked:border-2 disabled:border-border-disabled border-border-default" aria-required="true" type="checkbox" value="1" name="form_component_preview_test_model[option_one]" id="form_component_preview_test_model_option_one" /><svg class="cfa-icon absolute inset-0 pointer-events-none text-icon-default" width="24" height="24" aria-hidden="true" focusable="false"><use href="/assets/uswds-sprite-36dd7ae2.svg#check"></use></svg></span>
<label for="form_component_preview_test_model_option_one">Option one</label>
</div>
</div>
</div>
<div class="cfa-card bg-white border border-border-secondary rounded-lg p-cfa-lg">
<div class="cfa-stack-sm">
<div class="flex items-center gap-cfa-sm">
<span class="cfa-checkbox-wrap relative inline-flex h-6 w-6"><input name="form_component_preview_test_model[option_two]" type="hidden" value="" autocomplete="off" /><input class="cfa-checkbox h-6 w-6 rounded border checked:border-2 disabled:border-border-disabled border-border-default" aria-required="true" type="checkbox" value="1" name="form_component_preview_test_model[option_two]" id="form_component_preview_test_model_option_two" /><svg class="cfa-icon absolute inset-0 pointer-events-none text-icon-default" width="24" height="24" aria-hidden="true" focusable="false"><use href="/assets/uswds-sprite-36dd7ae2.svg#check"></use></svg></span>
<label for="form_component_preview_test_model_option_two">Option two</label>
</div>
</div>
</div>
</div>
</fieldset>
</form>
1
2
3
4
5
6
7
8
9
10
11
<%= form_with url: "/", method: :post, model: FormComponentPreview::TestModel.new do |f| %>
<%= render ExclusiveCheckboxGroupComponent.new(legend: "Which of these apply to you?") do %>
<%= render CardComponent.new do %>
<%= render SingleCheckboxComponent.new(form: f, method: :option_one, label: "Option one") %>
<% end %>
<%= render CardComponent.new do %>
<%= render SingleCheckboxComponent.new(form: f, method: :option_two, label: "Option two") %>
<% end %>
<% end %>
<% end %>