Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Bugfixes:

- Use #underscore, not #downcase for help text scope (#140, @atipugin)
- Radio button and checkbox labels will now include the disabled class as needed. (#156, @ScottSwezey)
- Fixed issue with setting offset in form_group without label in horizontal layout
when form uses non-default label_col

Features:

Expand Down
5 changes: 2 additions & 3 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ def form_group(*args, &block)

if get_group_layout(options[:layout]) == :horizontal
control_class = (options[:control_col] || control_col.clone)

unless options[:label]
control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || default_label_col))
control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || @label_col))
control_class.concat(" #{control_offset}")
end
control = content_tag(:div, control, class: control_class)
Expand Down Expand Up @@ -343,7 +342,7 @@ def generate_label(id, name, options, custom_label_col, group_layout)
end

def generate_help(name, help_text)
help_text = object.errors[name].join(", ") if has_error?(name) && inline_errors
help_text = get_error_messages(name) if has_error?(name) && inline_errors
return if help_text === false

help_text ||= get_help_text_by_i18n_key(name)
Expand Down
10 changes: 10 additions & 0 deletions test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,14 @@ def setup
expected = %{<form accept-charset="UTF-8" action="/users" class="form-horizontal" id="new_user" method="post" role="form"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div><div class="form-group"><label class="control-label required" for="user_email">Email</label><input class="form-control" id="user_email" name="user[email]" type="email" value="steve@example.com" /></div></form>}
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline }
end

test "non-default column span on form is reflected in form_group" do
non_default_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3", control_col: "col-sm-9" })
output = non_default_horizontal_builder.form_group do
%{<p class="form-control-static">Bar</p>}.html_safe
end

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