-
Notifications
You must be signed in to change notification settings - Fork 12
/
form.html.erb
284 lines (255 loc) · 17 KB
/
form.html.erb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<% if respond_to?(:form_with) %>
<h1>form_with</h1>
<h3>Horizontal Form</h3>
<%= bootstrap_form_with model: @user, scope: "user_a", url: "/", bootstrap: {layout: :horizontal} do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.collection_select :locale, [["English", "en"], ["French", "fr"]], :last, :first, bootstrap: {label: {text: "Language 2"}} %>
<%= form.date_select :date %>
<%= form.datetime_select :datetime %>
<%= form.time_select :time %>
<%= form.rich_text_area :rich_content, bootstrap: {label: "ActiveText Input", help: "Help Text"} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
<h3>Horizontal Form With Errors</h3>
<%= bootstrap_form_with model: @user_with_error, scope: "user_b", url: "/", bootstrap: {layout: :horizontal} do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.collection_select :locale, [["English", "en"], ["French", "fr"]], :last, :first, bootstrap: {label: {text: "Language 2"}} %>
<%= form.date_select :date %>
<%= form.datetime_select :datetime %>
<%= form.time_select :time %>
<%= form.rich_text_area :rich_content, bootstrap: {label: "ActiveText Input", help: "Help Text"} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
<h3>Inline Form</h3>
<%= bootstrap_form_with scope: :login, url: "/", bootstrap: {layout: :inline, label: {hide: true}} do |form| %>
<%= form.text_field :username, placeholder: "Username", bootstrap: {prepend: "@"} %>
<%= form.password_field :password, placeholder: "Password" %>
<%= form.check_box :remember_me %>
<%= form.primary "Sign in", class: "ml-3" %>
<% end %>
<div class="row">
<div class="col-md-6">
<h3>Vertical Form</h3>
<%= bootstrap_form_with model: @user, scope: "user_c", url: "/" do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<%= bootstrap_form_with model: @user_with_error, scope: "user_c", url: "/" do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3>Checkboxes and Radio buttons</h3>
<% @user.test = "b" %>
<%= bootstrap_form_with model: @user, scope: "user_d", url: "/" do |form| %>
<%= form.check_box :test, bootstrap: { label: "Singular Checkbox"} %>
<%= form.radio_button :test, "value_a", bootstrap: { label: "Singular Radio A"} %>
<%= form.radio_button :test, "value_b", bootstrap: { label: "Singular Radio B"} %>
<%= form.collection_radio_buttons :test, [["a", "Label A"], ["b", "Label B"]], :first, :second %>
<%= form.collection_check_boxes :test, [["e", "Label E"], ["f", "Label F"]], :first, :second, bootstrap: {help: "help text"} %>
<%= form.collection_radio_buttons :test, ["u", "v", "w"], :to_s, :to_s, bootstrap: {check_inline: true, label: {text: "Custom Label"}} %>
<%= form.collection_check_boxes :test, ["x", "y", "z"], :to_s, :to_s, bootstrap: {check_inline: true, help: "help text", label: {hide: true}} %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<% @user_with_error.test = "b" %>
<%= bootstrap_form_with model: @user_with_error, scope: "user_e", url: "/" do |form| %>
<%= form.check_box :test, bootstrap: { label: "Singular Checkbox"} %>
<%= form.radio_button :test, "value_a", bootstrap: { label: "Singular Radio A"} %>
<%= form.radio_button :test, "value_b", bootstrap: { label: "Singular Radio B"} %>
<%= form.collection_radio_buttons :test, [["a", "Label A"], ["b", "Label B"]], :first, :second %>
<%= form.collection_check_boxes :test, [["e", "Label E"], ["f", "Label F"]], :first, :second, bootstrap: {help: "help text"} %>
<%= form.collection_radio_buttons :test, ["u", "v", "w"], :to_s, :to_s, bootstrap: {check_inline: true, label: {text: "Custom Label"}} %>
<%= form.collection_check_boxes :test, ["x", "y", "z"], :to_s, :to_s, bootstrap: {check_inline: true, help: "help text", label: {hide: true}} %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3>Input Group</h3>
<%= bootstrap_form_with model: @user, scope: "user_f", url: "/" do |form| %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {prepend: "Prepend", append: "Append", help: "help text"} %>
<% prepend_button = capture do %>
<button class="btn btn-success">Go</button>
<% end %>
<% append_button = capture do %>
<button class="btn btn-danger">Stop</button>
<% end %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {label: {hide: true}, prepend: {html: prepend_button}, append: {html: append_button}} %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<%= bootstrap_form_with model: @user_with_error, scope: "user_g", url: "/" do |form| %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {prepend: "Prepend", append: "Append", help: "help text"} %>
<% prepend_button = capture do %>
<button class="btn btn-success">Go</button>
<% end %>
<% append_button = capture do %>
<button class="btn btn-danger">Stop</button>
<% end %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {label: {hide: true}, prepend: {html: prepend_button}, append: {html: append_button}} %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3>Custom Input Fields</h3>
<%= bootstrap_form_with model: @user, scope: "user_x", url: "/" do |form| %>
<%= form.file_field :test_a, placeholder: "Choose File", bootstrap: {label: {text: "Custom File Field"}, custom_control: true, help: "Help Text"} %>
<%= form.check_box :test_b, bootstrap: {label: {text: "Custom Checkbox"}, custom_control: true, help: "Help Text"} %>
<%= form.collection_radio_buttons :test_c, ["a", "b", "c"], :to_s, :to_s, bootstrap: {custom_control: true, label: {text: "Custom Radio Buttons"}, help: "Help text"} %>
<%= form.collection_check_boxes :test_d, ["x", "y", "z"], :to_s, :to_s, bootstrap: {custom_control: true, check_inline: true, label: {text: "Custom Checkboxes Inline"}, help: "Help Text"} %>
<%= form.select :test_e, [%w[Foo foo], %w[Bar bar], %w[Baz baz]], bootstrap: {custom_control: true, label: {text: "Custom Select"}, help: "Help Text"} %>
<%= form.date_select :test_f, bootstrap: {custom_control: true, label: {text: "Custom Date Select"} } %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<%= bootstrap_form_with model: @user_with_error, scope: "user_y", url: "/" do |form| %>
<%= form.file_field :test_a, placeholder: "Choose File", bootstrap: {label: {text: "Custom File Field"}, custom_control: true, help: "Help Text"} %>
<%= form.check_box :test_b, bootstrap: {label: {text: "Custom Checkbox"}, custom_control: true, help: "Help Text"} %>
<%= form.collection_radio_buttons :test_c, ["a", "b", "c"], :to_s, :to_s, bootstrap: {custom_control: true, label: {text: "Custom Radio Buttons"}, help: "Help text"} %>
<%= form.collection_check_boxes :test_d, ["x", "y", "z"], :to_s, :to_s, bootstrap: {custom_control: true, check_inline: true, label: {text: "Custom Checkboxes Inline"}, help: "Help Text"} %>
<%= form.select :test_e, [%w[Foo foo], %w[Bar bar], %w[Baz baz]], bootstrap: {custom_control: true, label: {text: "Custom Select"}, help: "Help Text"} %>
<%= form.date_select :test_f, bootstrap: {custom_control: true, label: {text: "Custom Date Select"} } %>
<% end %>
</div>
</div>
<% end %>
<h1>form_for</h1>
<h3>Horizontal Form</h3>
<%= bootstrap_form_for @user, as: "user_h", url: "/", bootstrap: {layout: :horizontal} do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
<h3>Horizontal Form With Errors</h3>
<%= bootstrap_form_for @user_with_error, as: "user_i", url: "/", bootstrap: {layout: :horizontal} do |form| %>
<%= form.text_field :username, placeholder: "AzureDiamond", bootstrap: {prepend: "@"} %>
<%= form.email_field :email, placeholder: "[email protected]" %>
<%= form.password_field :password, placeholder: "hunter2", bootstrap: {help: "Password should be at least 12 characters long"} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {check_inline: true, help: "Choose your favorite color"} %>
<%= form.text_area :bio, placeholder: "Tell us your life story" %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {label: {text: "Language"}} %>
<%= form.check_box :terms, bootstrap: {label: {text: "I agree to Terms and Conditions"}, help: "By clicking Agree you're also acknowledging that Apple may sew your mouth to a ... "} %>
<%= form.primary "Press to Register" do %>
<a href="/" class="btn btn-link">Maybe Later</a>
<% end %>
<% end %>
<h3>Inline Form</h3>
<%= bootstrap_form_for @user, as: "user_k", url: "/", bootstrap: {layout: :inline, label: {hide: true}} do |form| %>
<%= form.text_field :username, placeholder: "Username", bootstrap: {prepend: "@"} %>
<%= form.password_field :password, placeholder: "Password" %>
<%= form.primary "Sign in", class: "ml-3" %>
<% end %>
<div class="row">
<div class="col-md-6">
<h3>Checkboxes and Radio buttons</h3>
<% @user.test = "b" %>
<%= bootstrap_form_for @user, as: "user_l", url: "/" do |form| %>
<%= form.collection_radio_buttons :test, [["a", "Label A"], ["b", "Label B"]], :first, :second %>
<%= form.collection_check_boxes :test, [["e", "Label E"], ["f", "Label F"]], :first, :second, bootstrap: {help: "help text"} %>
<%= form.collection_radio_buttons :test, ["u", "v", "w"], :to_s, :to_s, bootstrap: {check_inline: true, label: {text: "Custom Label"}} %>
<%= form.collection_check_boxes :test, ["x", "y", "z"], :to_s, :to_s, bootstrap: {check_inline: true, help: "help text", label: {hide: true}} %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<% @user_with_error.test = "b" %>
<%= bootstrap_form_for @user_with_error, as: "user_m", url: "/" do |form| %>
<%= form.collection_radio_buttons :test, [["a", "Label A"], ["b", "Label B"]], :first, :second %>
<%= form.collection_check_boxes :test, [["e", "Label E"], ["f", "Label F"]], :first, :second, bootstrap: {help: "help text"} %>
<%= form.collection_radio_buttons :test, ["u", "v", "w"], :to_s, :to_s, bootstrap: {check_inline: true, label: {text: "Custom Label"}} %>
<%= form.collection_check_boxes :test, ["x", "y", "z"], :to_s, :to_s, bootstrap: {check_inline: true, help: "help text", label: {hide: true}} %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h3>Input Group</h3>
<%= bootstrap_form_for @user, as: "user_n", url: "/" do |form| %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {prepend: "Prepend", append: "Append", help: "help text"} %>
<% prepend_button = capture do %>
<button class="btn btn-success">Go</button>
<% end %>
<% append_button = capture do %>
<button class="btn btn-danger">Stop</button>
<% end %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {label: {hide: true}, prepend: {html: prepend_button}, append: {html: append_button}} %>
<% end %>
</div>
<div class="col-md-6">
<h3>With Errors</h3>
<%= bootstrap_form_for @user_with_error, as: "user_o", url: "/" do |form| %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {prepend: "Prepend", append: "Append", help: "help text"} %>
<% prepend_button = capture do %>
<button class="btn btn-success">Go</button>
<% end %>
<% append_button = capture do %>
<button class="btn btn-danger">Stop</button>
<% end %>
<%= form.email_field :email, placeholder: "Enter Email", bootstrap: {label: {hide: true}, prepend: {html: prepend_button}, append: {html: append_button}} %>
<% end %>
</div>
</div>
<h3>Disabled Bootstrap</h3>
<%= bootstrap_form_for @user, as: "user_p", url: "/", bootstrap: {layout: :horizontal} do |form| %>
<%= form.email_field :email, placeholder: "[email protected]", bootstrap: {disabled: true} %>
<%= form.select :locale, [["English", "en"], ["French", "fr"]], bootstrap: {disabled: true} %>
<%= form.file_field :test_a, bootstrap: {disabled: true} %>
<%= form.check_box :terms, bootstrap: {disabled: true} %>
<%= form.collection_radio_buttons :color, ["red", "green", "blue"], :to_s, :titleize, bootstrap: {disabled: true} %>
<%= form.collection_check_boxes :test, [["e", "Label E"], ["f", "Label F"]], :first, :second, bootstrap: {disabled: true} %>
<%= form.datetime_select :datetime, bootstrap: {disabled: true} %>
<%= form.submit "Submit", bootstrap: {disabled: true} %>
<% end %>
<div class="alert alert-primary">
Demo running on Rails <%= Rails.version %>
<div>