diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f6acc32..87e0cdabc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Bugfixes: - Allow objects without `model_name`s to act as form objects (#295, @laserlemon) + - Fix offset for submit for horizontal forms when using non-sm column breakers for label column (#293, @oteyatosys) - Your contribution here! Features: diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index d7f9c27ba..d89c96643 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -206,7 +206,7 @@ def form_group(*args, &block) if get_group_layout(options[:layout]) == :horizontal control_class = options[:control_col] || control_col unless options[:label] - control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || @label_col)) + control_offset = offset_col(options[:label_col] || @label_col) control_class = "#{control_class} #{control_offset}" end control = content_tag(:div, control, class: control_class) @@ -242,8 +242,8 @@ def default_label_col "col-sm-2" end - def offset_col(offset) - "col-sm-offset-#{offset}" + def offset_col(label_col) + label_col.sub(/^col-(\w+)-(\d)$/, 'col-\1-offset-\2') end def default_control_col diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 748f9c446..f9485e86d 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -146,6 +146,11 @@ def setup assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' } end + test "offset for form group without label respects label width for horizontal forms" do + expected = %{
} + assert_equal expected, bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10') { |f| f.form_group { f.submit } } + end + test "custom input width for horizontal forms" do expected = %{} assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' }