Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Bugfixes:

- Minor README corrections (#184, @msmithstubbs)
- Fixed label for bug with specified id (#213, #221, @datWav)

Features:

Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def convert_form_tag_options(method, options = {})
end

def generate_label(id, name, options, custom_label_col, group_layout)
options[:for] = id if acts_like_form_tag
options[:for] = id if acts_like_form_tag || !id.nil?
classes = [options[:class], label_class]
classes << (custom_label_col || label_col) if get_group_layout(group_layout) == :horizontal
classes << "required" if required_attribute?(object, name)
Expand Down
7 changes: 6 additions & 1 deletion test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def setup
assert_equal expected, @builder.text_field(:email, skip_label: true)
end

test "change label for attribute with specified id" do
expected = %{<div class="form-group"><label class="control-label required" for="blabla_blub">Email</label><input class="form-control" id="blabla_blub" name="user[email]" type="text" value="steve@example.com" /></div>}
assert_equal expected, @builder.text_field(:email, id: 'blabla_blub')
end

test "adding prepend text" do
expected = %{<div class="form-group"><label class="control-label required" 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>}
assert_equal expected, @builder.text_field(:email, prepend: '@')
Expand Down Expand Up @@ -252,5 +257,5 @@ def setup

expected = %{<div class="form-group"><div class="col-sm-9 col-sm-offset-3"><p class="form-control-static">Bar</p></div></div>}
assert_equal expected, output
end
end
end