Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default form-inline class applied to parent content div on date select helpers #461

Merged
merged 2 commits into from
Sep 13, 2018
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 @@ -6,6 +6,7 @@

### New features

* [461](https://github.com/bootstrap-ruby/bootstrap_form/pull/461): default form-inline class applied to parent content div on date select helpers. Can override with a :skip_inline option on the field helper - [@lancecarlson](https://github.com/lancecarlson).
* Your contribution here!

### Bugfixes
Expand Down Expand Up @@ -51,6 +52,7 @@ In addition to these necessary markup changes, the bootstrap_form API itself has
* [#449](https://github.com/bootstrap-ruby/bootstrap_form/pull/449): Passing `.form-row` overrides default `.form-group.row` in horizontal layouts.
* Added an option to the `submit` (and `primary`, by transitivity) form tag helper, `render_as_button`, which when truthy makes the submit button render as a button instead of an input. This allows you to easily provide further styling to your form submission buttons, without requiring you to reinvent the wheel and use the `button` helper (and having to manually insert the typical Bootstrap classes). - [@jsaraiva](https://github.com/jsaraiva).
* Add `:error_message` option to `check_box` and `radio_button`, so they can output validation error messages if needed. [@lcreid](https://github.com/lcreid).
* Your contribution here!

### Bugfixes

Expand Down
6 changes: 5 additions & 1 deletion lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def initialize(object_name, object, template, options)

define_method(with_method_name) do |name, options = {}, html_options = {}|
form_group_builder(name, options, html_options) do
content_tag(:div, class: control_specific_class(method_name)) do
html_class = control_specific_class(method_name)
if @layout == :horizontal && !options[:skip_inline].present?
html_class = "#{html_class} form-inline"
end
content_tag(:div, class: html_class) do
input_with_error(name) do
send(without_method_name, name, options, html_options)
end
Expand Down
27 changes: 27 additions & 0 deletions test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,33 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
assert_equivalent_xml expected, @builder.date_select(:misc, wrapper_class: "none-margin")
end
end

test "date selects inline when layout is horizontal" do
Timecop.freeze(Time.utc(2012, 2, 3)) do
expected = <<-HTML.strip_heredoc
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post" role="form">
<input name="utf8" type="hidden" value="&#x2713;"/>
<div class="form-group row">
<label class="col-form-label col-sm-2" for="user_misc">Misc</label>
<div class="col-sm-10">
<div class="rails-bootstrap-forms-date-select form-inline">
<select class="form-control" id="user_misc_1i" name="user[misc(1i)]">
#{options_range(start: 2007, stop: 2017, selected: 2012)}
</select>
<select class="form-control" id="user_misc_2i" name="user[misc(2i)]">
#{options_range(start: 1, stop: 12, selected: 2, months: true)}
</select>
<select class="form-control" id="user_misc_3i" name="user[misc(3i)]">
#{options_range(start: 1, stop: 31, selected: 3)}
</select>
</div>
</div>
</div>
</form>
HTML
assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.date_select(:misc) }
end
end

test "date selects are wrapped correctly with error" do
@user.errors.add(:misc, "error for test")
Expand Down