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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Bugfixes:

- Minor README corrections (#184, @msmithstubbs)
- Fix `alias_method_chain` deprecation warnings when using Rails 5
- Allow `form_group` to work with frozen string options

Features:

Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ def form_group(*args, &block)
control.concat(generate_icon(options[:icon])) if options[:icon]

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This offers a slight memory improvement since it's only creating new string objects as needed, instead of cloning every time.

unless options[:label]
control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || @label_col))
control_class.concat(" #{control_offset}")
control_class = "#{control_class} #{control_offset}"
end
control = content_tag(:div, control, class: control_class)
end
Expand Down
10 changes: 9 additions & 1 deletion test/bootstrap_form_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,13 @@ 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

test "non-default column span on form isn't mutated" do
frozen_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3".freeze, control_col: "col-sm-9".freeze })
output = frozen_horizontal_builder.form_group { 'test' }

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