Skip to content
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
4255abb
has-error is now has-danger
desheikh Nov 8, 2016
d8c3c1d
inputs with errors should have form-control-feedback
desheikh Nov 8, 2016
04388cf
control-label is now form-control-label
desheikh Nov 8, 2016
47e90fa
btn-default is now btn-secondary
desheikh Nov 8, 2016
2fe6f28
form-horizontal is no longer a required class
desheikh Nov 8, 2016
fd2dc57
input field should have form-control-danger on error
desheikh Nov 8, 2016
77ed9ff
checkbox is now form-check
desheikh Nov 8, 2016
edac96a
checkbox input should have form-check-input
desheikh Nov 8, 2016
7d4043e
non inline checkbox labels should have form-check-label
desheikh Nov 8, 2016
16d82d6
Support :prepend and :append for the `select` helper (#327)
donv Apr 24, 2017
4c83ea2
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Aug 28, 2017
5d4dec3
`form_with` mostly working.
lcreid Aug 28, 2017
41e1c79
Make it parse under Ruby 1.9.2
lcreid Sep 14, 2017
7fbe027
Try another way to fix Ruby 1.9.2 parse problem.
lcreid Sep 14, 2017
ace7723
Try Ruby 1.9.2 syntax yet again.
lcreid Sep 14, 2017
33ea133
Close, but going to try keying on Rails ID generation.
lcreid Sep 21, 2017
ce707de
Using the underlying option for id generation works.
lcreid Sep 21, 2017
9a45e86
Use fields instead of fields_for.
lcreid Sep 21, 2017
f9ebdec
Finally remove FormBuilderFormWith.
lcreid Sep 21, 2017
efd1122
Remove some unnecessary diffs.
lcreid Oct 7, 2017
637248a
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 9, 2018
75a9c39
Fix select test case for :prepend, :append.
lcreid Jan 9, 2018
c9fca28
Fix test case that hadn't been converted to form_with.
lcreid Jan 11, 2018
17259d1
Documentation tests.
lcreid Jan 11, 2018
1a1e4ec
Fix out-of-date HTML in test case.
lcreid Jan 11, 2018
fb2c3e0
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 11, 2018
4e1664b
Uncomment and fix Rails 5.1 collection_radio_button tests.
lcreid Jan 11, 2018
c2e8473
Merge branch 'minitest' into bootstrap-4-rails-5-1
lcreid Jan 11, 2018
db3ed98
Fix README to remove false statements about 5.2.
lcreid Jan 11, 2018
35606bb
heredoc
lcreid Jan 11, 2018
8f2973d
bootstrap_form_with_test working with 5.1 and 5.2.
lcreid Jan 12, 2018
d0f81bf
Handle Rails 5.1 and 5.2+.
lcreid Jan 12, 2018
300c8cf
Use heredoc.strip.
lcreid Jan 12, 2018
88858be
Comments and more heredoc formatting.
lcreid Jan 12, 2018
7881fbe
Merge branch 'master' into bootstrap-4-rails-5-1
lcreid Jan 16, 2018
6642309
Partially updated test cases.
lcreid Jan 16, 2018
62904ab
Don't add class="" to label if no classes specified.
lcreid Jan 16, 2018
4f89877
Merge branch 'empty-class-on-label' into bootstrap-4-rails-5-1
lcreid Jan 16, 2018
855764f
Intermediate check-in.
lcreid Jan 16, 2018
fa3fd46
Intermediate.
lcreid Jan 16, 2018
749b297
Intermediate.
lcreid Jan 16, 2018
71b8237
Intermediate.
lcreid Jan 17, 2018
1087a94
Most of custom IDs working.
lcreid Jan 17, 2018
fcb71ca
Uncomment test cases.
lcreid Jan 17, 2018
d02e1b7
Merge branch 'master' into empty-class-on-label
lcreid Jan 17, 2018
84c0591
Resolve conflicts.
lcreid Jan 17, 2018
f8f18c3
Merge branch 'empty-class-on-label' into bootstrap-4-rails-5-1
lcreid Jan 17, 2018
287d2a4
Saving work with tests red and debugging.
lcreid Jan 18, 2018
606ee0d
Commit before saving to future branch.
lcreid Jan 18, 2018
e55246b
Delete redundant test files.
lcreid Jan 18, 2018
6b9d6f7
Remove puts and TODOs.
lcreid Jan 18, 2018
855e948
Tests passing up to Rails 5.1.
lcreid Jan 18, 2018
72e1aac
Some tests for form_with. All pass.
lcreid Jan 19, 2018
2607af9
Documentation tested.
lcreid Jan 19, 2018
710cf10
Update Rails 5.1 examples in documentation.
lcreid Jan 19, 2018
1b15bb5
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 19, 2018
ac7d2bc
Pin minitest to exactly 5.10.1 for Rails 5.0.
lcreid Jan 19, 2018
f315716
Fence off one form_with test.
lcreid Jan 19, 2018
14c74a4
Add tests for fields method. Pass when they shouldn't.
lcreid Jan 20, 2018
f766d0b
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 21, 2018
69e76ab
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 21, 2018
e86b7f9
Go back to using minitest 5.10.3 to do bisect.
lcreid Jan 22, 2018
7f97507
Merge branch 'master' into bootstrap-4-rails-5-1
lcreid Jan 23, 2018
102cc54
Merge remote-tracking branch 'upstream/master' into bootstrap-4-rails…
lcreid Jan 23, 2018
fc2db34
Test only form_for in one case.
lcreid Jan 23, 2018
df5dd0d
Test and show that bootstrap_form fields helper not needed
lcreid Jan 23, 2018
0991706
Merge branch 'master' into bootstrap-4-rails-5-1
lcreid Jan 25, 2018
2855154
Remove unwanted tests.
lcreid Jan 25, 2018
f85f628
Feedback from review.
lcreid Jan 25, 2018
b01a5f4
Minimize test cases.
lcreid Jan 25, 2018
b81c30b
Fix mistaken commit of version.
lcreid Jan 25, 2018
af121f3
Remove code per review.
lcreid Jan 25, 2018
4a028c5
Remove duplicate CHANGELOG entry
mattbrictson Jan 26, 2018
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 @@ -11,6 +11,7 @@ Bugfixes:

Features:
- Your contribution here!
- [#369]Support for Rails 5.1 `form_with` - [@lcreid](https://github.com/lcreid).
- new `custom: true` option for radio buttons and check boxes according to bootstrap 4.0.0.beta3
- Allow HTML in help translations by using the '_html' suffix on the key - [@unikitty37](https://github.com/unikitty37)
* [#325](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/325): Support :prepend and :append for the `select` helper - [@donv](https://github.com/donv).
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end

group :test do
# can relax version requirement for Rails 5.2.beta3+
gem "minitest", "~> 5.10.3"
gem "minitest", "5.10.1"

gem "diffy"
gem "equivalent-xml"
Expand Down
142 changes: 141 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Bootstrap v4-style forms into your Rails application.
## Requirements

* Ruby 2.3+
* Rails 5.0+
* Rails 5.0+ (Rails 5.1+ for `bootstrap_form_with`)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* Bootstrap 4.0.0-beta.3+

## Installation
Expand All @@ -40,6 +40,138 @@ Then require the CSS in your `application.css` file:

## Usage

### Rails >= 5.1
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think we should go as far as recommend form_with for Rails 5.1. IMHO the form_with released in 5.1 is fundamentally broken as it does not include IDs. I personally would wait until 5.2 to make the leap from form_for to form_with.

Perhaps we could re-title this section with a caveat:

### `bootstrap_form_with` (Rails 5.1+)

Note that `form_with` in Rails 5.1 does not add IDs to form elements and labels by default, which are both important to Bootstrap markup. This behavior is corrected in Rails 5.2.

And place it after the section where we describe:

### `bootstrap_form_for` (Rails 5.0+)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I wrote the README relatively early in my work on this PR, and once I actually started to use form_with in my own app I was feeling that form_with in 5.1 wasn't really ready for prime time.


To get started, just use the `bootstrap_form_with` helper
in place of `form_with`. Here's an example:

```erb
<%= bootstrap_form_with(model: @user, local: true) do |f| %>
<%= f.email_field :email %>
<%= f.password_field :password %>
<%= f.check_box :remember_me %>
<%= f.submit "Log In" %>
<% end %>
```

This generates:

```html
<form role="form" action="/users" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label class="required" for="user_email">Email</label>
<input class="form-control" type="email" value="steve@example.com" name="user[email]" />
</div>
<div class="form-group">
<label for="user_password">Password</label>
<input class="form-control" type="password" name="user[password]" />
<small class="form-text text-muted">A good password should be at least six characters long</small>
</div>
<div class="form-check">
<label class="form-check-label" for="user_remember_me">
<input name="user[remember_me]" type="hidden" value="0" />
<input class="form-check-input" type="checkbox" value="1" name="user[remember_me]" /> Remember me</label>
</div>
<input type="submit" name="commit" value="Log In" class="btn btn-secondary" data-disable-with="Log In" />
</form>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplication. Should be sufficient to to say that bootstrap_form_with is the same thing as bootstrap_form_for and the only difference being that it takes same arguments as form_with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Stand-alone" bootstrap_form_with documentation should be easier to update when bootstrap_form_for goes away. Also, users often appreciate examples they can just cut and paste.

```

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is sufficient to stop here, with a note that says that both model: and url: styles are supported. We don't need to reproduce all the Rails documentation. (Perhaps a link to the appropriate section of the Rails doc would be nice.) In particular, I would remove these sections as well:

  • Important Differences Between form_with and form_for
  • Ajax by Default
  • No Default DOM IDs
  • Use fields Instead Of fields_for In Nested Forms
  • No Default Classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Back in September, when I was first trying my fork with bootstrap_form_with, this section brought together the things I was learning about form_with versus form_for. But now I'm sure I can find a good link to differences, so I'll take this section out and replace it with a link or two to other documentation.

If your form is not backed by a model, use `bootstrap_form_with` like this:

```erb
<%= bootstrap_form_with url: '/subscribe', local: true do |f| %>
<%= f.email_field :email, value: 'name@example.com' %>
<%= f.submit %>
<% end %>
```

```html
<form role="form" action="/subscribe" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label for="email">Email</label>
<input value="name@example.com" class="form-control" type="email" name="email" />
</div>
<input type="submit" name="commit" value="Save " class="btn btn-secondary" data-disable-with="Save " />
</form>
```

#### Important Differences Between `form_with` and `form_for`
Copy link
Contributor

Choose a reason for hiding this comment

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

Link to Rails documentation would be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some users may appreciate a summary of the differences/tricks about using form_with versus form_for. If everyone things this is overly redundant or pedantic, by all means I'll remove it.


Rails 5.1 introduced `form_with`,
which unifies the functionality previously found in `form_for` and `form_tag`.
`form_for` and `form_tag` will be deprecated in a future version of Rails,
so new applications should use `bootstrap_form_with`.

`form_with` is different compared to `form_for` and `form_tag`.
`bootstrap_form_width` basically just wraps `form_with`
and adds some functionality,
and so the different behaviour of `form_with`
is reflected in `bootstrap_form_with`
compared to `bootstrap_form_for`
and `bootstrap_form_tag`.

##### Ajax by Default
`form_with` defaults to submitting forms via Javascript XHR calls,
like `form_for` or `form_tag` would do if you specified `remote: true`.
If you want the browser to submit the request
the same way `form_for` and `form_tag` would do by default,
you need to specify `local: true` as an option to `form_with`.

##### No Default DOM IDs
Copy link
Contributor

Choose a reason for hiding this comment

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

That's out-of-date and incorrect.

Edit: Correct for 5.1, not correct for 5.2 (rails/rails@d3893ec) unless it gets back-ported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. I saw that the Rails PR had been merged, but in my rush to submit this PR, I didn't fix the README.

Copy link
Contributor Author

@lcreid lcreid Jan 11, 2018

Choose a reason for hiding this comment

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

I've fixed up the README. I need to test against Rails 5.2. Will I be able to do that after #366 is merged, or do I need to figure out how to test against Rails 5.2 myself?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can just temporarily add gem "rails", "5.2.0.beta3" in Gemfile to test it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @GBH . I could only find beta2 on rubygems.org, but that's good enough for me for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to slow down and read stuff instead of jumping to conclusions. The commit @GBH referenced (rails/rails@d3893ec) is not the commit I thought it was. I will have to rethink this. The commit makes Rails 5.2+ easier to work with, but I'll have to think about how to document Rails 5.1 and form_with.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like every form_with test may have to have a 5.1 and 5.2+ version. There's already too much duplication to test form_with and form_for. I'll think about this, but if anyone has any suggestions, I'd love to hear them.

tl;dr of the problem: form_with in Rails 5.1 doesn't generate any DOM IDs in the HTML. It looks like form_with in Rails 5.2 is going back to generating DOM IDs in the HTML by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

The thing is, you don't need to duplicate every single test there is. It's enough to make one for textfield and assume that all others work the same.

When used with the builder (variable) yielded by `form_with`,
the Rails field helpers do not generate a default DOM id.
Because `bootstrap_form_width` just wraps and adds some functionality
to `form_with`,
the `bootstrap_form_with` field helpers also do not generate a default DOM id.
This affect how labels work in your application,
and may affect automated testing if you're using Capybara or similar tools,
and you wrote actions or tests that selected on the DOM id of an element.

For Rails 5.1, you can specify the id explicitly in most cases:

```erb
<%= bootstrap_form_with(model: @user, local: true) do |f| %>
<%= f.email_field :email %>
<%= f.password_field :password, id: :password %>
<%= f.submit "Log In" %>
<% end %>
```

generates:

```html
<form role="form" action="/users" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="&#x2713;" />
<div class="form-group">
<label class="required" for="user_email">Email</label>
<input class="form-control" type="email" value="steve@example.com" name="user[email]" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input id="password" class="form-control" type="password" name="user[password]" />
<small class="form-text text-muted">A good password should be at least six characters long</small>
</div>
<input type="submit" name="commit" value="Log In" class="btn btn-secondary" data-disable-with="Log In" />
</form>
```

##### Use `fields` Instead Of `fields_for` In Nested Forms
For nested forms, use `fields` instead of `fields_for`.

##### No Default Classes
Finally, `bootstrap_form_with` doesn't attach a default class
to the form.
If you attached styling to the DOM class that `form_for` added to the form element,
you'll have to add your own code to attach the appropriate class.

#### Nested Forms with `bootstrap_form_with`

This hasn't been tested yet.

### Rails < 5.1

Copy link
Contributor

Choose a reason for hiding this comment

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

Some of this is documentation of form_with. Readme should contain info relevant to the library, and not what it wraps. Nobody wants to read a wall of text. Duplicating rendered html produced by bootstrap_form_for and bootstrap_form_with is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that there's a lot of HTML in the README. I was just following the outline of the documentation for form_for.

To get started, just use the `bootstrap_form_for` helper. Here's an example:

```erb
Expand Down Expand Up @@ -84,6 +216,14 @@ If your form is not backed by a model, use the `bootstrap_form_tag`. Usage of th
<% end %>
```

### Future Compatibility

The Rails team has suggested that `form_for` and `form_tag`
may be deprecated and then removed in future versions of Rails.
`bootstrap_form` will continue to support
`bootstrap_form_for` and `bootstrap_form_tag`
as long as Rails supports `form_for` and `form_tag`.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great clarification 👍

Could you remove the hard line wrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. An old nroff habit.


## Form Helpers

This gem wraps the following Rails form helpers:
Expand Down
38 changes: 24 additions & 14 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class FormBuilder < ActionView::Helpers::FormBuilder
attr_reader :layout, :label_col, :control_col, :has_error, :inline_errors, :label_errors, :acts_like_form_tag

FIELD_HELPERS = %w{color_field date_field datetime_field datetime_local_field
email_field month_field number_field password_field phone_field
range_field search_field telephone_field text_area text_field time_field
url_field week_field}
email_field month_field number_field password_field phone_field
range_field search_field telephone_field text_area text_field time_field
url_field week_field}

DATE_SELECT_HELPERS = %w{date_select time_select datetime_select}

Expand Down Expand Up @@ -194,7 +194,7 @@ def collection_check_boxes_with_bootstrap(*args)
options[:multiple] = true
check_box(name, options, value, nil)
end
hidden_field(args.first,{value: "", multiple: true}).concat(html)
hidden_field(args.first, {value: "", multiple: true}).concat(html)
end

bootstrap_method_alias :collection_check_boxes
Expand Down Expand Up @@ -234,7 +234,10 @@ def form_group(*args, &block)
end

def fields_for_with_bootstrap(record_name, record_object = nil, fields_options = {}, &block)
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
if record_object.is_a?(Hash) && record_object.extractable_options?
fields_options = record_object
record_object = nil
end
fields_options[:layout] ||= options[:layout]
fields_options[:label_col] = fields_options[:label_col].present? ? "#{fields_options[:label_col]}" : options[:label_col]
fields_options[:control_col] ||= options[:control_col]
Expand All @@ -245,6 +248,8 @@ def fields_for_with_bootstrap(record_name, record_object = nil, fields_options =

bootstrap_method_alias :fields_for

# TODO: Add `fields_with_bootstrap` method and alias

private

def horizontal?
Expand Down Expand Up @@ -300,11 +305,11 @@ def required_attribute?(obj, attribute)
end

has_presence_validator = target_validators.include?(
ActiveModel::Validations::PresenceValidator)
ActiveModel::Validations::PresenceValidator)

if defined? ActiveRecord::Validations::PresenceValidator
has_presence_validator |= target_validators.include?(
ActiveRecord::Validations::PresenceValidator)
ActiveRecord::Validations::PresenceValidator)
end

has_presence_validator
Expand All @@ -313,6 +318,7 @@ def required_attribute?(obj, attribute)
def form_group_builder(method, options, html_options = nil)
options.symbolize_keys!
html_options.symbolize_keys! if html_options
options[:id] = html_options[:id] if html_options && @options[:skip_default_ids]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain why this line is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure this is part my attempt to handle what is more elegantly handled in #357. The (minimized) tests pass without this line, so I'll take it out.


# Add control_class; allow it to be overridden by :control_class option
css_options = html_options || options
Expand Down Expand Up @@ -356,11 +362,11 @@ def form_group_builder(method, options, html_options = nil)
label_text ||= options.delete(:label)
end

form_group_options.merge!(label: {
form_group_options[:label] = {
text: label_text,
class: label_class,
skip_required: options.delete(:skip_required)
})
}
end

form_group(method, form_group_options) do
Expand All @@ -369,13 +375,19 @@ def form_group_builder(method, options, html_options = nil)
end

def convert_form_tag_options(method, options = {})
options[:name] ||= method
options[:id] ||= method
unless @options[:skip_default_ids]
options[:name] ||= method
options[:id] ||= method
end
options
end

def generate_label(id, name, options, custom_label_col, group_layout)
options[:for] = id if acts_like_form_tag
# id is the caller's options[:id] at the only place this method is called.
# The options argument is a small subset of the options that might have
# been passed to generate_label's caller, and definitely doesn't include
# :id.
options[:for] = id if acts_like_form_tag || id
Copy link
Contributor

Choose a reason for hiding this comment

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

I am also having trouble figuring out this part. If id is present, then it will be assigned regardless of whether acts_like_form_tag is true or false. Why is the acts_like_form_tag check needed at all, then?

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 was to address part of the consequence of no default IDs in Rails 5.1 form_with. I'll take this out, and let it be handled by #357. And yes, the acts_like_form_tag becomes redundant when I added || id. "Doh!" I don't know what I was thinking. :-)

classes = [options[:class]]
classes << (custom_label_col || label_col) if get_group_layout(group_layout) == :horizontal
unless options.delete(:skip_required)
Expand All @@ -392,7 +404,6 @@ def generate_label(id, name, options, custom_label_col, group_layout)
else
label(name, options[:text], options.except(:text))
end

end

def generate_help(name, help_text)
Expand Down Expand Up @@ -461,6 +472,5 @@ def get_help_text_by_i18n_key(name)
help_text
end
end

end
end
32 changes: 26 additions & 6 deletions lib/bootstrap_form/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ module Helper
def bootstrap_form_for(object, options = {}, &block)
options.reverse_merge!({builder: BootstrapForm::FormBuilder})

options[:html] ||= {}
options[:html][:role] ||= 'form'

if options[:layout] == :inline
options[:html][:class] = [options[:html][:class], "form-inline"].compact.join(" ")
end
options = process_options(options)

temporarily_disable_field_error_proc do
form_for(object, options, &block)
Expand All @@ -22,6 +17,31 @@ def bootstrap_form_tag(options = {}, &block)
bootstrap_form_for("", options, &block)
end

def bootstrap_form_with(options = {}, &block)
options.reverse_merge!(builder: BootstrapForm::FormBuilder)

options = process_options(options)

temporarily_disable_field_error_proc do
form_with(options, &block)
end
end

private

def process_options(options)
options[:html] ||= {}
options[:html][:role] ||= 'form'

if options[:layout] == :inline
options[:html][:class] = [options[:html][:class], 'form-inline'].compact.join(' ')
end

options
end

public

def temporarily_disable_field_error_proc
original_proc = ActionView::Base.field_error_proc
ActionView::Base.field_error_proc = proc { |input, instance| input }
Expand Down
Loading