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
90
<script type="text/javascript"> window.addEventListener('load', function () { document.querySelector('input#country_us').onclick = function() { document.querySelector('primer-multi-input').activateField('states'); }; document.querySelector('input#country_ca').onclick = function() { document.querySelector('primer-multi-input').activateField('provinces'); }; }, false);</script><form action="/view-components/rails-app/multi.json" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="y_-Q-MUzMR0D7kOT88lN_lRU18vK2sdgL2s0J5CpnLYUKBttvvVBAwhWcnZj9fdwQVzqm8P89dtqyPOrSyOeBg" autocomplete="off" /> <div class="FormControl-spacingWrapper"> <div data-view-component="true"> <div class="FormControl-radio-group-wrap"> <fieldset aria-describedby="validation-f7ba45b8-2198-4b0a-b5a4-ba19dd7ad45f" class=""> <legend class="FormControl-label"> Country </legend> <div class="mb-2"> </div> <div class="FormControl-spacingWrapper"> <div class="FormControl-radio-wrap"> <input class="FormControl-radio" type="radio" value="US" name="country" id="country_us" /> <span class="FormControl-radio-labelWrap"> <label class="FormControl-label" for="country_us"> USA </label> </span> </div> <div class="FormControl-radio-wrap"> <input class="FormControl-radio" type="radio" value="CA" name="country" id="country_ca" /> <span class="FormControl-radio-labelWrap"> <label class="FormControl-label" for="country_ca"> Canada </label> </span> </div> </div> </fieldset> <div class="mt-2"> <div class="FormControl-inlineValidation" id="validation-f7ba45b8-2198-4b0a-b5a4-ba19dd7ad45f" 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 data-view-component="true"> <div aria-describedby="validation-2c942061-29fd-4cec-a627-a62522f75783" class="FormControl width-full FormControl--fullWidth"> <label class="FormControl-label" for="region"> Region </label> <primer-multi-input data-name="region"> <div class="FormControl-select-wrap"> <select data-name="states" data-targets="primer-multi-input.fields" aria-describedby="validation-fda66c27-9a32-4d07-b314-c549ee78dbaa" class="FormControl-select FormControl-medium" name="region" id="region"><option value="CA">California</option> <option value="WA">Washington</option> <option value="OR">Oregon</option></select> </div> <div class="FormControl-select-wrap" hidden="hidden"> <select hidden="hidden" data-name="provinces" data-targets="primer-multi-input.fields" disabled="disabled" aria-describedby="validation-f694319b-f31a-4003-add0-424cbd22ddc3" class="FormControl-select FormControl-medium" name="region" id="region"><option value="BC">British Columbia</option> <option value="AB">Alberta</option> <option value="SK">Saskatchewan</option></select> </div> </primer-multi-input> <div class="FormControl-inlineValidation" id="validation-2c942061-29fd-4cec-a627-a62522f75783" 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 data-view-component="true"> <button name="submit" value="Submit" data-disable-with="Submit" type="submit" data-view-component="true" class="FormField-input flex-self-start Button--primary Button--medium Button"> <span class="Button-content"> <span class="Button-label">Submit</span> </span> </button> </div> </div></form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script type="text/javascript"> window.addEventListener('load', function () { document.querySelector('input#country_us').onclick = function() { document.querySelector('primer-multi-input').activateField('states'); }; document.querySelector('input#country_ca').onclick = function() { document.querySelector('primer-multi-input').activateField('provinces'); }; }, false);</script><%= primer_form_with(url: multi_index_path(format: :json)) do |f| %> <%= render(MultiInputForm.new(f)) %><% end %>
No notes provided.
No params configured.
app/forms/multi_input_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
# frozen_string_literal: true# :nodoc:class MultiInputForm < ApplicationForm form do |my_form| my_form.radio_button_group(name: :country, label: "Country") do |radio_group| radio_group.radio_button(label: "USA", value: "US") radio_group.radio_button(label: "Canada", value: "CA") end my_form.multi(name: :region, label: "Region") do |region| region.select_list(name: :states) do |state_list| state_list.option(label: "California", value: "CA") state_list.option(label: "Washington", value: "WA") state_list.option(label: "Oregon", value: "OR") end region.select_list(hidden: true, name: :provinces) do |province_list| province_list.option(label: "British Columbia", value: "BC") province_list.option(label: "Alberta", value: "AB") province_list.option(label: "Saskatchewan", value: "SK") end end my_form.submit(name: :submit, label: "Submit", scheme: :primary) endend