Skip to content

Commit 21a823e

Browse files
oteyatosysmattbrictson
authored andcommitted
Fix offset_col to match label with for non-sm column classes (#293)
* Fix offset_col to match label with for non-sm column classes * Adding fix column offset fix description to changelog
1 parent ed591c1 commit 21a823e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Bugfixes:
44
- Allow objects without `model_name`s to act as form objects (#295, @laserlemon)
5+
- Fix offset for submit for horizontal forms when using non-sm column breakers for label column (#293, @oteyatosys)
56
- Your contribution here!
67

78
Features:

lib/bootstrap_form/form_builder.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def form_group(*args, &block)
206206
if get_group_layout(options[:layout]) == :horizontal
207207
control_class = options[:control_col] || control_col
208208
unless options[:label]
209-
control_offset = offset_col(/([0-9]+)$/.match(options[:label_col] || @label_col))
209+
control_offset = offset_col(options[:label_col] || @label_col)
210210
control_class = "#{control_class} #{control_offset}"
211211
end
212212
control = content_tag(:div, control, class: control_class)
@@ -242,8 +242,8 @@ def default_label_col
242242
"col-sm-2"
243243
end
244244

245-
def offset_col(offset)
246-
"col-sm-offset-#{offset}"
245+
def offset_col(label_col)
246+
label_col.sub(/^col-(\w+)-(\d)$/, 'col-\1-offset-\2')
247247
end
248248

249249
def default_control_col

test/bootstrap_form_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def setup
146146
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' }
147147
end
148148

149+
test "offset for form group without label respects label width for horizontal forms" do
150+
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"><div class="col-md-10 col-md-offset-2"><input class="btn btn-default" name="commit" type="submit" value="Create User" /></div></div></form>}
151+
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 } }
152+
end
153+
149154
test "custom input width for horizontal forms" do
150155
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 col-sm-2 required" for="user_email">Email</label><div class="col-sm-5"><input class="form-control" id="user_email" name="user[email]" type="email" value="[email protected]" /></div></div></form>}
151156
assert_equal expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' }

0 commit comments

Comments
 (0)