Skip to content

Commit 9e085e6

Browse files
committed
Fixes disabled radio button labels
1 parent 402face commit 9e085e6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/bootstrap_form/form_builder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ def radio_button_with_bootstrap(name, value, *args)
124124
args << options.except(:label, :help, :inline)
125125

126126
html = radio_button_without_bootstrap(name, value, *args) + " " + options[:label]
127+
disabled_class = options[:disabled] ? " disabled" : ""
127128

128129
if options[:inline]
129-
label(name, html, class: "radio-inline", value: value)
130+
label(name, html, class: "radio-inline#{disabled_class}", value: value)
130131
else
131-
content_tag(:div, class: "radio") do
132+
content_tag(:div, class: "radio#{disabled_class}") do
132133
label(name, html, value: value)
133134
end
134135
end

test/bootstrap_radio_button_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ def setup
1717
assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true)
1818
end
1919

20+
test "radio_button disabled label is set correctly" do
21+
expected = %{<div class="radio disabled"><label for="user_misc_1"><input disabled="disabled" id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label></div>}
22+
assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', disabled: true)
23+
end
24+
25+
test "radio_button disabled inline label is set correctly" do
26+
expected = %{<label class="radio-inline disabled" for="user_misc_1"><input disabled="disabled" id="user_misc_1" name="user[misc]" type="radio" value="1" /> This is a radio button</label>}
27+
assert_equal expected, @builder.radio_button(:misc, '1', label: 'This is a radio button', inline: true, disabled: true)
28+
end
29+
2030
test 'collection_radio_buttons renders the form_group correctly' do
2131
collection = [Address.new(id: 1, street: 'Foobar')]
2232
expected = %{<div class="form-group"><label class="control-label" for="user_misc">This is a radio button collection</label><div class="radio"><label for="user_misc_1"><input id="user_misc_1" name="user[misc]" type="radio" value="1" /> Foobar</label></div><span class="help-block">With a help!</span></div>}

0 commit comments

Comments
 (0)