Skip to content

Commit de7e93d

Browse files
committed
Allow array values for the label_col and control_col options.
Fixes #703
1 parent e7cb208 commit de7e93d

File tree

5 files changed

+6
-7
lines changed

5 files changed

+6
-7
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
log/*.log
44
pkg/
55
demo/db/*.sqlite3
6-
demo/doc/screenshots/**/*.committed.png
7-
demo/doc/screenshots/**/*.latest.png
6+
demo/doc/screenshots/**/*.diff.png
87
demo/log/*.log
98
demo/tmp/
109
*.gem

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ The `label_col` and `control_col` css classes can also be changed per control:
12141214
```erb
12151215
<%= bootstrap_form_for(@user, layout: :horizontal) do |f| %>
12161216
<%= f.email_field :email %>
1217-
<%= f.text_field :age, label_col: "col-sm-3", control_col: "col-sm-3" %>
1217+
<%= f.text_field :age, label_col: %w[col-sm-3 text-bg-info], control_col: %w[col-sm-3 text-bg-success] %>
12181218
<%= f.check_box :terms, label_col: "", control_col: "col-sm-11" %>
12191219
<%= f.form_group do %>
12201220
<%= f.submit %>
@@ -1233,8 +1233,8 @@ This generates:
12331233
</div>
12341234
</div>
12351235
<div class="mb-3 row">
1236-
<label class="col-form-label col-sm-3" for="user_age">Age</label>
1237-
<div class="col-sm-3">
1236+
<label class="col-form-label col-sm-3 text-bg-info" for="user_age">Age</label>
1237+
<div class="col-sm-3 text-bg-success">
12381238
<input class="form-control" id="user_age" name="user[age]" type="text" value="42">
12391239
</div>
12401240
</div>
90 Bytes
Loading

lib/bootstrap_form/form_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def default_label_col
104104
end
105105

106106
def offset_col(label_col)
107-
label_col.gsub(/\bcol-(\w+)-(\d)\b/, 'offset-\1-\2')
107+
[*label_col].flat_map { |s| s.split(/\s+/) }.grep(/^col-/).join(" ").gsub(/\bcol-(\w+)-(\d)\b/, 'offset-\1-\2')
108108
end
109109

110110
def default_control_col

test/bootstrap_form_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def warn(message, ...)
686686
</form>
687687
HTML
688688
assert_equivalent_html expected,
689-
bootstrap_form_for(@user, layout: :horizontal, label_col: "col-sm-4 col-md-2",
689+
bootstrap_form_for(@user, layout: :horizontal, label_col: %w[col-sm-4 col-md-2],
690690
control_col: "col-sm-8 col-md-10") { |f| f.form_group { f.submit } }
691691
end
692692

0 commit comments

Comments
 (0)