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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<form action="/foo" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="7ICwwbuvYXBLuuP8R_YcYsbjWcf2uPb46Uk-vxyI2Glo4DyW_DMGxORs_w9zVYxhun1FEcIb7sRk1fbG2UTRRw" autocomplete="off" /> <div class="FormControl-spacingWrapper"> <div data-view-component="true"> <div class="FormControl-check-group-wrap"> <fieldset aria-describedby="validation-b325dbdb-bd73-4665-a6de-773f6068aef6 caption-b325dbdb-bd73-4665-a6de-773f6068aef6" class=""> <legend class="FormControl-label"> City categories </legend> <div class="mb-2"> <span class="FormControl-caption" id="caption-b325dbdb-bd73-4665-a6de-773f6068aef6"> Select all that apply. </span> </div> <div class="FormControl-spacingWrapper"> <div class="FormControl-checkbox-wrap"> <input aria-describedby="caption-a4549682-0289-45f2-a502-8154197f11f2" id="city_categories_capital" class="FormControl-checkbox" type="checkbox" value="capital" name="city_categories[]" /> <span class="FormControl-checkbox-labelWrap"> <label for="city_categories_capital" class="FormControl-label"> Capital </label> <span class="FormControl-caption" id="caption-a4549682-0289-45f2-a502-8154197f11f2"> The capital city </span> </span> </div> <div class="FormControl-checkbox-wrap"> <input aria-describedby="caption-a3ecd324-b30a-48ea-8a4f-46e16c7f12d9" id="city_categories_populous" class="FormControl-checkbox" type="checkbox" value="populous" name="city_categories[]" /> <span class="FormControl-checkbox-labelWrap"> <label for="city_categories_populous" class="FormControl-label"> Most-populous </label> <span class="FormControl-caption" id="caption-a3ecd324-b30a-48ea-8a4f-46e16c7f12d9"> The five most-populous cities </span> </span> </div> <div class="FormControl-checkbox-wrap"> <input aria-describedby="caption-92212919-ad19-4f92-834d-117a6caf1f6d" id="city_categories_custom" class="FormControl-checkbox" type="checkbox" value="custom" name="city_categories[]" /> <span class="FormControl-checkbox-labelWrap"> <label for="city_categories_custom" class="FormControl-label"> Custom </label> <span class="FormControl-caption" id="caption-92212919-ad19-4f92-834d-117a6caf1f6d"> A custom list of cities </span> </span> </div> <div class="ml-4"> <div class="FormControl-spacingWrapper"> <div data-view-component="true"> <primer-text-field class="FormControl width-full FormControl--fullWidth"> <label id="label-3c639eb5-28a9-4ff6-98db-31b81b799393" class="FormControl-label" for="custom_cities"> Custom cities </label> <div class="FormControl-input-wrap"> <input aria-describedby="validation-3c639eb5-28a9-4ff6-98db-31b81b799393 caption-3c639eb5-28a9-4ff6-98db-31b81b799393" data-target="primer-text-field.inputElement " class="FormControl-input FormControl-medium" type="text" name="custom_cities" id="custom_cities" /> </div> <div class="FormControl-inlineValidation" id="validation-3c639eb5-28a9-4ff6-98db-31b81b799393" hidden="hidden"> <span class="FormControl-inlineValidation--visual" data-target="primer-text-field.validationSuccessIcon" hidden><svg aria-hidden="true" height="12" viewBox="0 0 12 12" version="1.1" width="12" data-view-component="true" class="octicon octicon-check-circle-fill"> <path d="M6 0a6 6 0 1 1 0 12A6 6 0 0 1 6 0Zm-.705 8.737L9.63 4.403 8.392 3.166 5.295 6.263l-1.7-1.702L2.356 5.8l2.938 2.938Z"></path> </svg></span> <span class=" FormControl-inlineValidation--visual" data-target="primer-text-field.validationErrorIcon"><svg aria-hidden="true" height="12" viewBox="0 0 12 12" version="1.1" width="12" data-view-component="true" class="octicon octicon-alert-fill"> <path d="M4.855.708c.5-.896 1.79-.896 2.29 0l4.675 8.351a1.312 1.312 0 0 1-1.146 1.954H1.33A1.313 1.313 0 0 1 .183 9.058ZM7 7V3H5v4Zm-1 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"></path> </svg></span> <span></span> </div> <span class="FormControl-caption" id="caption-3c639eb5-28a9-4ff6-98db-31b81b799393"> A space-separated list of cities </span> </primer-text-field> </div> </div> </div> </div> </fieldset> <div class="mt-2"> <div class="FormControl-inlineValidation" id="validation-b325dbdb-bd73-4665-a6de-773f6068aef6" hidden="hidden"> <span class="FormControl-inlineValidation--visual" data-target="" hidden><svg aria-hidden="true" height="12" viewBox="0 0 12 12" version="1.1" width="12" data-view-component="true" class="octicon octicon-check-circle-fill"> <path d="M6 0a6 6 0 1 1 0 12A6 6 0 0 1 6 0Zm-.705 8.737L9.63 4.403 8.392 3.166 5.295 6.263l-1.7-1.702L2.356 5.8l2.938 2.938Z"></path> </svg></span> <span class=" FormControl-inlineValidation--visual" data-target=""><svg aria-hidden="true" height="12" viewBox="0 0 12 12" version="1.1" width="12" data-view-component="true" class="octicon octicon-alert-fill"> <path d="M4.855.708c.5-.896 1.79-.896 2.29 0l4.675 8.351a1.312 1.312 0 0 1-1.146 1.954H1.33A1.313 1.313 0 0 1 .183 9.058ZM7 7V3H5v4Zm-1 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"></path> </svg></span> <span></span> </div> </div> </div> </div> </div></form>1
2
3
<%= primer_form_with(url: "/foo") do |f| %> <%= render(CheckBoxWithNestedForm.new(f)) %><% end %>No notes provided.
No params configured.
app/forms/check_box_with_nested_form.rb
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
# frozen_string_literal: true# :nodoc:class CheckBoxWithNestedForm < ApplicationForm # :nodoc: class CustomCitiesForm < ApplicationForm form do |custom_cities_form| custom_cities_form.text_field( name: :custom_cities, label: "Custom cities", caption: "A space-separated list of cities" ) end end form do |check_form| check_form.check_box_group( name: :city_categories, label: "City categories", caption: "Select all that apply." ) do |check_group| check_group.check_box( value: "capital", label: "Capital", caption: "The capital city" ) check_group.check_box( value: "populous", label: "Most-populous", caption: "The five most-populous cities" ) check_group.check_box( value: "custom", label: "Custom", caption: "A custom list of cities" ) do |custom_check_box| custom_check_box.nested_form do |builder| CustomCitiesForm.new(builder) end end end endend