Skip to content

Commit 6b0ca0b

Browse files
committed
Merge pull request #145 from atipugin/skip_label
Allow to skip label rendering
2 parents 7d35352 + dd552e6 commit 6b0ca0b

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ This gem wraps the following Rails form helpers:
115115
* time_zone_select
116116
* url_field
117117
* week_field
118-
118+
119119
These helpers accept the same options as the standard Rails form helpers, with
120120
a few extra options:
121121

@@ -360,6 +360,12 @@ using screen readers.
360360
<% end %>
361361
```
362362

363+
To skip label rendering at all, use `skip_label: true` option.
364+
365+
```erb
366+
<%= f.password_field :password, skip_label: true %>
367+
```
368+
363369
### Horizontal Forms
364370

365371
To use a horizontal-layout form with labels to the left of the control, use the

lib/bootstrap_form/form_builder.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ def form_group_builder(method, options, html_options = nil)
272272
layout = get_group_layout(options.delete(:layout))
273273
form_group_options = {
274274
id: options[:id],
275-
label: {
276-
text: label,
277-
class: label_class
278-
},
279275
help: help,
280276
icon: icon,
281277
label_col: label_col,
@@ -288,6 +284,13 @@ def form_group_builder(method, options, html_options = nil)
288284
form_group_options.reverse_merge!(wrapper_options)
289285
end
290286

287+
unless options.delete(:skip_label)
288+
form_group_options.reverse_merge!(label: {
289+
text: label,
290+
class: label_class
291+
})
292+
end
293+
291294
form_group(method, form_group_options) do
292295
yield
293296
end

test/bootstrap_form_group_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def setup
1717
assert_equal expected, @builder.text_field(:email, hide_label: true)
1818
end
1919

20+
test "skipping a label" do
21+
expected = %{<div class="form-group"><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div>}
22+
assert_equal expected, @builder.text_field(:email, skip_label: true)
23+
end
24+
2025
test "adding prepend text" do
2126
expected = %{<div class="form-group"><label class="control-label" for="user_email">Email</label><div class="input-group"><span class="input-group-addon">@</span><input class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" /></div></div>}
2227
assert_equal expected, @builder.text_field(:email, prepend: '@')

0 commit comments

Comments
 (0)