Fullscreen/bh — pull request #32 by claudiob (2014-09-19 16:50:37+00:00)
Title: Add `:fieldset` option to `fields_for`.

By default `fields_for` wraps the fields in a `

` tag (which is styled as a panel).
After this commit, the behavior can be disabled by passing the `fieldset: false` option to `fields_for`.

---

After this commit, here is how you can wrap fields in a form.

1. Without any fieldset: just use the field helpers inside the form

```rhtml
<%= f.text_field :budget, prefix:'$' %>
<%= f.text_field :cost_per_unit, prefix: '$' %>
```
![1](https://cloud.githubusercontent.com/assets/10076/4338791/db95eef8-401c-11e4-9b8d-cc5cb096748e.png)

2. With a fieldset that does not uses a panel: manually add the `

..

` around the fields. I think that this is not a common case: why would someone specify that some fields create a "field set" and not separate them from the rest? Anyway, if that's the case, it can still be achieved (and looks like 1.):

```rhtml

<%= f.text_field :budget, prefix:'$' %>
<%= f.text_field :cost_per_unit, prefix: '$' %>

```
![2](https://cloud.githubusercontent.com/assets/10076/4338792/dd5a13ea-401c-11e4-9485-1062e7ed43da.png)

3. With a fieldset that uses a panel: use the `fieldset` helper (with or without optional title):

```rhtml
<%= f.fieldset 'Price' do %>
<%= f.text_field :budget, prefix:'$' %>
<%= f.text_field :cost_per_unit, prefix: '$' %>
<% end %>
```
![3](https://cloud.githubusercontent.com/assets/10076/4338795/e2b256c2-401c-11e4-878c-c95cb96670dd.png)

4. With a fields_for that wraps fields in a `

` tag (and therefore looks like 3.): use the `fields_for` helper:

```rhtml
<%= f.fields_for :price do |price_f| %>
<%= price_f.text_field :budget, prefix:'$' %>
<%= price_f.text_field :cost_per_unit, prefix: '$' %>
<% end %>
```
![4](https://cloud.githubusercontent.com/assets/10076/4338796/e44c63d8-401c-11e4-9357-bcd1f47784cb.png)

5. With a fields_for that does not wrap fields in a `

` tag (and therefore looks like 1. and 2.): use the `fields_for` helper with the `fieldset: false` option:

```rhtml
<%= f.fields_for :price, fieldset: false do |price_f| %>
<%= price_f.text_field :budget, prefix:'$' %>
<%= price_f.text_field :cost_per_unit, prefix: '$' %>
<% end %>
```
![5](https://cloud.githubusercontent.com/assets/10076/4338797/e59c4168-401c-11e4-9a2a-2e927f3558ae.png)