comfy_bootstrap_form 4.0.0.beta1 → 4.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +12 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +40 -0
- data/Gemfile +14 -0
- data/{MIT-LICENSE → LICENSE.md} +1 -1
- data/README.md +130 -495
- data/Rakefile +5 -15
- data/bootstrap_form.gemspec +25 -0
- data/demo/README.md +18 -0
- data/demo/Rakefile +6 -0
- data/demo/app/controllers/application_controller.rb +2 -0
- data/demo/app/controllers/bootstrap_controller.rb +12 -0
- data/demo/app/models/application_record.rb +3 -0
- data/demo/app/models/user.rb +3 -0
- data/demo/app/views/bootstrap/form.html.erb +82 -0
- data/demo/app/views/layouts/application.html.erb +43 -0
- data/demo/bin/bundle +3 -0
- data/{test/dummy → demo}/bin/rails +1 -1
- data/{test/dummy → demo}/bin/rake +0 -0
- data/demo/bin/setup +36 -0
- data/demo/bin/update +31 -0
- data/demo/bin/yarn +11 -0
- data/{test/dummy → demo}/config.ru +2 -1
- data/demo/config/application.rb +24 -0
- data/demo/config/boot.rb +5 -0
- data/{test/dummy → demo}/config/database.yml +8 -12
- data/demo/config/environment.rb +5 -0
- data/demo/config/environments/development.rb +60 -0
- data/{test/dummy → demo}/config/environments/test.rb +15 -20
- data/demo/config/initializers/application_controller_renderer.rb +8 -0
- data/demo/config/initializers/assets.rb +14 -0
- data/{test/dummy → demo}/config/initializers/backtrace_silencers.rb +0 -0
- data/demo/config/initializers/cookies_serializer.rb +5 -0
- data/{test/dummy → demo}/config/initializers/filter_parameter_logging.rb +0 -0
- data/{test/dummy → demo}/config/initializers/inflections.rb +0 -0
- data/{test/dummy → demo}/config/initializers/mime_types.rb +0 -1
- data/{test/dummy → demo}/config/initializers/wrap_parameters.rb +2 -2
- data/{test/dummy → demo}/config/locales/en.yml +10 -0
- data/demo/config/puma.rb +56 -0
- data/{test/dummy → demo}/config/routes.rb +2 -0
- data/demo/config/spring.rb +6 -0
- data/demo/config/storage.yml +35 -0
- data/demo/db/schema.rb +11 -0
- data/{test/dummy/public/favicon.ico → demo/log/.keep} +0 -0
- data/demo/package.json +5 -0
- data/demo/public/favicon.ico +0 -0
- data/lib/bootstrap_form.rb +2 -2
- data/lib/bootstrap_form/form_builder.rb +367 -346
- data/lib/bootstrap_form/version.rb +1 -1
- data/lib/bootstrap_form/view_helper.rb +33 -0
- data/lib/comfy_bootstrap_form.rb +1 -1
- data/test/bootstrap_form/fields_test.rb +304 -0
- data/test/bootstrap_form/fields_with_errors_test.rb +109 -0
- data/test/bootstrap_form/form_builder_test.rb +49 -0
- data/test/bootstrap_form/horizontal_form_test.rb +159 -0
- data/test/bootstrap_form/inline_form_test.rb +68 -0
- data/test/bootstrap_form/input_group_test.rb +53 -0
- data/test/bootstrap_form/radios_and_checkboxes_test.rb +208 -0
- data/test/bootstrap_form/submit_test.rb +59 -0
- data/test/bootstrap_form/view_helpers_test.rb +99 -0
- data/test/gemfiles/5.2.gemfile +13 -0
- data/test/test_helper.rb +31 -69
- metadata +71 -258
- data/app/assets/stylesheets/rails_bootstrap_forms.css +0 -10
- data/lib/bootstrap_form/aliasing.rb +0 -35
- data/lib/bootstrap_form/helper.rb +0 -36
- data/lib/bootstrap_form/helpers/bootstrap.rb +0 -94
- data/lib/bootstrap_form/helpers/nested_form.rb +0 -33
- data/test/bootstrap_checkbox_test.rb +0 -144
- data/test/bootstrap_fields_test.rb +0 -152
- data/test/bootstrap_form_group_test.rb +0 -313
- data/test/bootstrap_form_test.rb +0 -276
- data/test/bootstrap_other_components_test.rb +0 -86
- data/test/bootstrap_radio_button_test.rb +0 -124
- data/test/bootstrap_selects_test.rb +0 -160
- data/test/dummy/Gemfile +0 -45
- data/test/dummy/Gemfile.lock +0 -120
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -10
- data/test/dummy/app/assets/javascripts/application.js +0 -16
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/address.rb +0 -3
- data/test/dummy/app/models/faux_user.rb +0 -9
- data/test/dummy/app/models/super_user.rb +0 -2
- data/test/dummy/app/models/user.rb +0 -9
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/config/application.rb +0 -23
- data/test/dummy/config/boot.rb +0 -4
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -29
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/initializers/generic_migration.rb +0 -6
- data/test/dummy/config/initializers/secret_token.rb +0 -12
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/db/migrate/20130703191909_create_users.rb +0 -13
- data/test/dummy/db/migrate/20130703191937_create_addresses.rb +0 -13
- data/test/dummy/db/migrate/20130912171202_add_preferences_to_user.rb +0 -5
- data/test/dummy/db/migrate/20140327190145_add_terms_to_user.rb +0 -5
- data/test/dummy/db/migrate/20140922133133_add_type_to_users.rb +0 -5
- data/test/dummy/db/schema.rb +0 -38
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +0 -18394
- data/test/dummy/public/404.html +0 -58
- data/test/dummy/public/422.html +0 -58
- data/test/dummy/public/500.html +0 -57
- data/test/dummy/public/robots.txt +0 -5
- data/test/dummy/test/fixtures/addresses.yml +0 -15
- data/test/dummy/test/fixtures/users.yml +0 -15
- data/test/dummy/test/models/address_test.rb +0 -7
- data/test/dummy/test/models/user_test.rb +0 -7
- data/test/dummy/test/test_helper.rb +0 -15
- data/test/special_form_class_models_test.rb +0 -43
@@ -0,0 +1,33 @@
|
|
1
|
+
module BootstrapForm
|
2
|
+
module ViewHelper
|
3
|
+
|
4
|
+
# Wrapper for `form_with`. Passing in Bootstrap form builder.
|
5
|
+
def bootstrap_form_with(**options, &block)
|
6
|
+
supress_field_errors do
|
7
|
+
css_classes = options.delete(:class) || ""
|
8
|
+
bootstrap_options = options[:bootstrap] || {}
|
9
|
+
|
10
|
+
if bootstrap_options[:layout].to_s == "inline"
|
11
|
+
css_classes << " form-inline"
|
12
|
+
end
|
13
|
+
|
14
|
+
form_options = options.reverse_merge(builder: BootstrapForm::FormBuilder)
|
15
|
+
form_options.merge!(class: css_classes) unless css_classes.blank?
|
16
|
+
form_with(**form_options, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# By default, Rails will wrap form fields with extra html to indicate
|
23
|
+
# inputs with errors. We need to handle this in the builder to render
|
24
|
+
# Bootstrap specific markup. So we need to bypass this.
|
25
|
+
def supress_field_errors
|
26
|
+
original_proc = ActionView::Base.field_error_proc
|
27
|
+
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
28
|
+
yield
|
29
|
+
ensure
|
30
|
+
ActionView::Base.field_error_proc = original_proc
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/comfy_bootstrap_form.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative "./bootstrap_form"
|
1
|
+
require_relative "./bootstrap_form"
|
@@ -0,0 +1,304 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class FieldsTest < ActionView::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@user = User.new
|
7
|
+
@builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_text_field
|
11
|
+
actual = @builder.text_field(:email)
|
12
|
+
expected = <<-HTML
|
13
|
+
<div class="form-group">
|
14
|
+
<label for="user_email">Email</label>
|
15
|
+
<input class="form-control" type="text" name="user[email]" id="user_email" />
|
16
|
+
</div>
|
17
|
+
HTML
|
18
|
+
assert_xml_equal expected, actual
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_text_field_label_text
|
22
|
+
actual = @builder.text_field(:email, bootstrap: {label: {text: "Custom Label"}})
|
23
|
+
expected = <<-HTML
|
24
|
+
<div class="form-group">
|
25
|
+
<label for="user_email">Custom Label</label>
|
26
|
+
<input class="form-control" type="text" name="user[email]" id="user_email" />
|
27
|
+
</div>
|
28
|
+
HTML
|
29
|
+
assert_xml_equal expected, actual
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_text_field_label_css_class
|
33
|
+
actual = @builder.text_field(:email, bootstrap: {label: {class: "custom_class"}})
|
34
|
+
expected = <<-HTML
|
35
|
+
<div class="form-group">
|
36
|
+
<label class="custom_class" for="user_email">Email</label>
|
37
|
+
<input class="form-control" type="text" name="user[email]" id="user_email" />
|
38
|
+
</div>
|
39
|
+
HTML
|
40
|
+
assert_xml_equal expected, actual
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_text_field_label_hide
|
44
|
+
actual = @builder.text_field(:email, bootstrap: {label: {hide: true}})
|
45
|
+
expected = <<-HTML
|
46
|
+
<div class="form-group">
|
47
|
+
<label class="sr-only" for="user_email">Email</label>
|
48
|
+
<input class="form-control" type="text" name="user[email]" id="user_email" />
|
49
|
+
</div>
|
50
|
+
HTML
|
51
|
+
assert_xml_equal expected, actual
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_text_field_control_css_class
|
55
|
+
actual = @builder.text_field(:email, class: "custom-class")
|
56
|
+
expected = <<-HTML
|
57
|
+
<div class="form-group">
|
58
|
+
<label for="user_email">Email</label>
|
59
|
+
<input class="custom-class form-control" type="text" name="user[email]" id="user_email" />
|
60
|
+
</div>
|
61
|
+
HTML
|
62
|
+
assert_xml_equal expected, actual
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_text_field_help_text
|
66
|
+
actual = @builder.text_field(:email, bootstrap: {help: "help text"})
|
67
|
+
expected = <<-HTML
|
68
|
+
<div class="form-group">
|
69
|
+
<label for="user_email">Email</label>
|
70
|
+
<input class="form-control" type="text" name="user[email]" id="user_email" />
|
71
|
+
<small class="form-text text-muted">help text</small>
|
72
|
+
</div>
|
73
|
+
HTML
|
74
|
+
assert_xml_equal expected, actual
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_select
|
78
|
+
actual = @builder.select(:test, %w[a b])
|
79
|
+
expected = <<-HTML
|
80
|
+
<div class="form-group">
|
81
|
+
<label for="user_test">Test</label>
|
82
|
+
<select class="form-control" id="user_test" name="user[test]">
|
83
|
+
<option value="a">a</option>
|
84
|
+
<option value="b">b</option>
|
85
|
+
</select>
|
86
|
+
</div>
|
87
|
+
HTML
|
88
|
+
assert_xml_equal expected, actual
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_select_control_css_class
|
92
|
+
actual = @builder.select(:test, %w[a b], {}, class: "custom")
|
93
|
+
expected = <<-HTML
|
94
|
+
<div class="form-group">
|
95
|
+
<label for="user_test">Test</label>
|
96
|
+
<select class="custom form-control" id="user_test" name="user[test]">
|
97
|
+
<option value="a">a</option>
|
98
|
+
<option value="b">b</option>
|
99
|
+
</select>
|
100
|
+
</div>
|
101
|
+
HTML
|
102
|
+
assert_xml_equal expected, actual
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_color_field
|
106
|
+
actual = @builder.color_field(:test)
|
107
|
+
expected = <<-HTML
|
108
|
+
<div class="form-group">
|
109
|
+
<label for="user_test">Test</label>
|
110
|
+
<input class="form-control" type="color" name="user[test]" id="user_test" value="#000000"/>
|
111
|
+
</div>
|
112
|
+
HTML
|
113
|
+
assert_xml_equal expected, actual
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_date_field
|
117
|
+
actual = @builder.date_field(:test)
|
118
|
+
expected = <<-HTML
|
119
|
+
<div class="form-group">
|
120
|
+
<label for="user_test">Test</label>
|
121
|
+
<input class="form-control" type="date" name="user[test]" id="user_test"/>
|
122
|
+
</div>
|
123
|
+
HTML
|
124
|
+
assert_xml_equal expected, actual
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_datetime_field
|
128
|
+
actual = @builder.datetime_field(:test)
|
129
|
+
expected = <<-HTML
|
130
|
+
<div class="form-group">
|
131
|
+
<label for="user_test">Test</label>
|
132
|
+
<input class="form-control" type="datetime-local" name="user[test]" id="user_test"/>
|
133
|
+
</div>
|
134
|
+
HTML
|
135
|
+
assert_xml_equal expected, actual
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_email_field
|
139
|
+
actual = @builder.email_field(:test)
|
140
|
+
expected = <<-HTML
|
141
|
+
<div class="form-group">
|
142
|
+
<label for="user_test">Test</label>
|
143
|
+
<input class="form-control" type="email" name="user[test]" id="user_test"/>
|
144
|
+
</div>
|
145
|
+
HTML
|
146
|
+
assert_xml_equal expected, actual
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_file_field
|
150
|
+
actual = @builder.file_field(:test)
|
151
|
+
expected = <<-HTML
|
152
|
+
<div class="form-group">
|
153
|
+
<label for="user_test">Test</label>
|
154
|
+
<input class="form-control" type="file" name="user[test]" id="user_test"/>
|
155
|
+
</div>
|
156
|
+
HTML
|
157
|
+
assert_xml_equal expected, actual
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_month_field
|
161
|
+
actual = @builder.month_field(:test)
|
162
|
+
expected = <<-HTML
|
163
|
+
<div class="form-group">
|
164
|
+
<label for="user_test">Test</label>
|
165
|
+
<input class="form-control" type="month" name="user[test]" id="user_test"/>
|
166
|
+
</div>
|
167
|
+
HTML
|
168
|
+
assert_xml_equal expected, actual
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_number_field
|
172
|
+
actual = @builder.number_field(:test)
|
173
|
+
expected = <<-HTML
|
174
|
+
<div class="form-group">
|
175
|
+
<label for="user_test">Test</label>
|
176
|
+
<input class="form-control" type="number" name="user[test]" id="user_test"/>
|
177
|
+
</div>
|
178
|
+
HTML
|
179
|
+
assert_xml_equal expected, actual
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_password_field
|
183
|
+
actual = @builder.password_field(:test)
|
184
|
+
expected = <<-HTML
|
185
|
+
<div class="form-group">
|
186
|
+
<label for="user_test">Test</label>
|
187
|
+
<input class="form-control" type="password" name="user[test]" id="user_test"/>
|
188
|
+
</div>
|
189
|
+
HTML
|
190
|
+
assert_xml_equal expected, actual
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_phone_field
|
194
|
+
actual = @builder.phone_field(:test)
|
195
|
+
expected = <<-HTML
|
196
|
+
<div class="form-group">
|
197
|
+
<label for="user_test">Test</label>
|
198
|
+
<input class="form-control" type="tel" name="user[test]" id="user_test"/>
|
199
|
+
</div>
|
200
|
+
HTML
|
201
|
+
assert_xml_equal expected, actual
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_range_field
|
205
|
+
actual = @builder.range_field(:test)
|
206
|
+
expected = <<-HTML
|
207
|
+
<div class="form-group">
|
208
|
+
<label for="user_test">Test</label>
|
209
|
+
<input class="form-control" type="range" name="user[test]" id="user_test"/>
|
210
|
+
</div>
|
211
|
+
HTML
|
212
|
+
assert_xml_equal expected, actual
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_search_field
|
216
|
+
actual = @builder.search_field(:test)
|
217
|
+
expected = <<-HTML
|
218
|
+
<div class="form-group">
|
219
|
+
<label for="user_test">Test</label>
|
220
|
+
<input class="form-control" type="search" name="user[test]" id="user_test"/>
|
221
|
+
</div>
|
222
|
+
HTML
|
223
|
+
assert_xml_equal expected, actual
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_text_area
|
227
|
+
actual = @builder.text_area(:test)
|
228
|
+
expected = <<-HTML
|
229
|
+
<div class="form-group">
|
230
|
+
<label for="user_test">Test</label>
|
231
|
+
<textarea class="form-control" name="user[test]" id="user_test"/></textarea>
|
232
|
+
</div>
|
233
|
+
HTML
|
234
|
+
assert_xml_equal expected, actual
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_time_field
|
238
|
+
actual = @builder.time_field(:test)
|
239
|
+
expected = <<-HTML
|
240
|
+
<div class="form-group">
|
241
|
+
<label for="user_test">Test</label>
|
242
|
+
<input class="form-control" type="time" name="user[test]" id="user_test"/>
|
243
|
+
</div>
|
244
|
+
HTML
|
245
|
+
assert_xml_equal expected, actual
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_url_field
|
249
|
+
actual = @builder.url_field(:test)
|
250
|
+
expected = <<-HTML
|
251
|
+
<div class="form-group">
|
252
|
+
<label for="user_test">Test</label>
|
253
|
+
<input class="form-control" type="url" name="user[test]" id="user_test"/>
|
254
|
+
</div>
|
255
|
+
HTML
|
256
|
+
assert_xml_equal expected, actual
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_week_field
|
260
|
+
actual = @builder.week_field(:test)
|
261
|
+
expected = <<-HTML
|
262
|
+
<div class="form-group">
|
263
|
+
<label for="user_test">Test</label>
|
264
|
+
<input class="form-control" type="week" name="user[test]" id="user_test"/>
|
265
|
+
</div>
|
266
|
+
HTML
|
267
|
+
assert_xml_equal expected, actual
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_plaintext
|
271
|
+
actual = @builder.plaintext(:test)
|
272
|
+
expected = <<-HTML
|
273
|
+
<div class="form-group">
|
274
|
+
<label for="user_test">Test</label>
|
275
|
+
<input class="form-control-plaintext" readonly="readonly" type="text" name="user[test]" id="user_test"/>
|
276
|
+
</div>
|
277
|
+
HTML
|
278
|
+
assert_xml_equal expected, actual
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_form_group
|
282
|
+
actual = @builder.form_group do
|
283
|
+
"test"
|
284
|
+
end
|
285
|
+
expected = <<-HTML
|
286
|
+
<div class="form-group">test</div>
|
287
|
+
HTML
|
288
|
+
assert_xml_equal expected, actual
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_form_group_with_label
|
292
|
+
actual = @builder.form_group(bootstrap: {label: {text: "Test"}}) do
|
293
|
+
"test"
|
294
|
+
end
|
295
|
+
expected = <<-HTML
|
296
|
+
<div class="form-group">
|
297
|
+
<label>Test</label>
|
298
|
+
test
|
299
|
+
</div>
|
300
|
+
HTML
|
301
|
+
assert_xml_equal expected, actual
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class FieldsWithErrorsTest < ActionView::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@user = User.new
|
7
|
+
@user.errors.add(:test, "invalid")
|
8
|
+
|
9
|
+
@builder = BootstrapForm::FormBuilder.new(:user, @user, self, {})
|
10
|
+
|
11
|
+
@original_proc = ActionView::Base.field_error_proc
|
12
|
+
ActionView::Base.field_error_proc = proc { |input, instance| input }
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
ActionView::Base.field_error_proc = @original_proc
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_text_field_with_error
|
20
|
+
actual = @builder.text_field(:test)
|
21
|
+
expected = <<-HTML
|
22
|
+
<div class="form-group">
|
23
|
+
<label for="user_test">Test</label>
|
24
|
+
<input class="form-control is-invalid" id="user_test" name="user[test]" type="text"/>
|
25
|
+
<div class="invalid-feedback">invalid</div>
|
26
|
+
</div>
|
27
|
+
HTML
|
28
|
+
assert_xml_equal expected, actual
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_check_box_with_error
|
32
|
+
actual = @builder.check_box(:test)
|
33
|
+
expected = <<-HTML
|
34
|
+
<fieldset class="form-group">
|
35
|
+
<div class="form-check">
|
36
|
+
<input name="user[test]" type="hidden" value="0"/>
|
37
|
+
<input class="form-check-input is-invalid" id="user_test" name="user[test]" type="checkbox" value="1"/>
|
38
|
+
<label class="form-check-label" for="user_test">Test</label>
|
39
|
+
<div class="invalid-feedback">invalid</div>
|
40
|
+
</div>
|
41
|
+
</fieldset>
|
42
|
+
HTML
|
43
|
+
assert_xml_equal expected, actual
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_collection_radio_buttons_with_error_and_help
|
47
|
+
actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {help: "help text"})
|
48
|
+
expected = <<-HTML
|
49
|
+
<fieldset class="form-group">
|
50
|
+
<legend class="col-form-label pt-0">Test</legend>
|
51
|
+
<div class="form-check">
|
52
|
+
<input class="form-check-input is-invalid" id="user_test_a" name="user[test]" type="radio" value="a"/>
|
53
|
+
<label class="form-check-label" for="user_test_a">A</label>
|
54
|
+
</div>
|
55
|
+
<div class="form-check">
|
56
|
+
<input class="form-check-input is-invalid" id="user_test_b" name="user[test]" type="radio" value="b"/>
|
57
|
+
<label class="form-check-label" for="user_test_b">B</label>
|
58
|
+
<div class="invalid-feedback">invalid</div>
|
59
|
+
<small class="form-text text-muted">help text</small>
|
60
|
+
</div>
|
61
|
+
</fieldset>
|
62
|
+
HTML
|
63
|
+
assert_xml_equal expected, actual
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_collection_radio_buttons_inline_with_error_and_help
|
67
|
+
actual = @builder.collection_radio_buttons(:test, ["a", "b"], :to_s, :titleize, bootstrap: {
|
68
|
+
inline: true,
|
69
|
+
help: "help text"
|
70
|
+
})
|
71
|
+
expected = <<-HTML
|
72
|
+
<fieldset class="form-group">
|
73
|
+
<legend class="col-form-label pt-0">Test</legend>
|
74
|
+
<div class="form-check form-check-inline">
|
75
|
+
<input class="form-check-input is-invalid" id="user_test_a" name="user[test]" type="radio" value="a"/>
|
76
|
+
<label class="form-check-label" for="user_test_a">A</label>
|
77
|
+
</div>
|
78
|
+
<div class="form-check form-check-inline">
|
79
|
+
<input class="form-check-input is-invalid" id="user_test_b" name="user[test]" type="radio" value="b"/>
|
80
|
+
<label class="form-check-label" for="user_test_b">B</label>
|
81
|
+
</div>
|
82
|
+
<div class="invalid-feedback">invalid</div>
|
83
|
+
<small class="form-text text-muted">help text</small>
|
84
|
+
</fieldset>
|
85
|
+
HTML
|
86
|
+
assert_xml_equal expected, actual
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_text_field_with_input_group_error
|
90
|
+
actual = @builder.text_field(:test, bootstrap: {prepend: "A", append: "Z"})
|
91
|
+
expected = <<-HTML
|
92
|
+
<div class="form-group">
|
93
|
+
<label for="user_test">Test</label>
|
94
|
+
<div class="input-group">
|
95
|
+
<div class="input-group-prepend">
|
96
|
+
<span class="input-group-text">A</span>
|
97
|
+
</div>
|
98
|
+
<input class="form-control is-invalid" id="user_test" name="user[test]" type="text"/>
|
99
|
+
<div class="input-group-append">
|
100
|
+
<span class="input-group-text">Z</span>
|
101
|
+
</div>
|
102
|
+
<div class="invalid-feedback">invalid</div>
|
103
|
+
</div>
|
104
|
+
</div>
|
105
|
+
HTML
|
106
|
+
assert_xml_equal expected, actual
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|