Skip to content

Commit 07ecebd

Browse files
committed
Check box label can now be disabled as per the bootstrap docs
1 parent ad3c9a5 commit 07ecebd

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Bugfixes:
44

55
- Use #underscore, not #downcase for help text scope (#140, @atipugin)
66
- Radio button labels will now include the disabled class as needed. (#156, @ScottSwezey)
7+
- Check box labels will now include the disabled class as needed. (@ScottSwezey)
78

89
Features:
910

lib/bootstrap_form/form_builder.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_
108108
label_name = name
109109
label_name = "#{name}_#{checked_value}" if options[:multiple]
110110

111+
disabled_class = options[:disabled] ? " disabled" : ""
112+
111113
if options[:inline]
112-
label(label_name, html, class: "checkbox-inline")
114+
label(label_name, html, class: "checkbox-inline#{disabled_class}")
113115
else
114-
content_tag(:div, class: "checkbox") do
116+
content_tag(:div, class: "checkbox#{disabled_class}") do
115117
label(label_name, html)
116118
end
117119
end

test/bootstrap_checkbox_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def setup
1212
assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms')
1313
end
1414

15+
test "disabled check_box has proper wrapper classes" do
16+
expected = %{<div class="checkbox disabled"><label for="user_terms"><input disabled="disabled" name="user[terms]" type="hidden" value="0" /><input disabled="disabled" id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the terms</label></div>}
17+
assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true)
18+
end
19+
1520
test "check_box label allows html" do
1621
expected = %{<div class="checkbox"><label for="user_terms"><input name="user[terms]" type="hidden" value="0" /><input id="user_terms" name="user[terms]" type="checkbox" value="1" /> I agree to the <a href="#">terms</a></label></div>}
1722
assert_equal expected, @builder.check_box(:terms, label: %{I agree to the <a href="#">terms</a>}.html_safe)

0 commit comments

Comments
 (0)