justinfrench/formtastic — Issue #735: Builder option to disable optional_string/required_string for a single input
Author: damncabbage
Created: 2011-11-04 05:11:25+00:00
State: open

I've set up Formtastic with the following options, in an effect to mimic something like [the field setup described here](http://uxmovement.com/forms/highlight-optional-form-fields-not-required-ones/) (ie. mark fields as optional, rather than required):

```ruby
Formtastic::FormBuilder.optional_string = " (optional)"
Formtastic::FormBuilder.required_string = ""
```

The only downside of this is that boolean fields always get the optional_string or required_string tacked on the end (see [inputs/boolean.rb](https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/boolean_input.rb#L67) and [inputs/base/labelling.rb](https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/base/labelling.rb#L23)). This can sometimes look odd with standalone boolean checkbox fields.

For example:

```
Upload (optional): [ ] [Browse]
[x] Remove file?
```

My current workaround is to duplicate the builder and blank the optional_string config manually; this is unfortunately a bit of a hack:

```erb
<%= f.inputs :for => :image do |builder| %>
<% label_builder = builder.dup %>
<% label_builder.optional_string = '' %>

<% builder.input :file %>

<% label_builder.input :remove_file, :as => :boolean, :label => "Remove this file?"%>
<% end %>
```

Maybe an `:optional_string => false` or similar passed in the `builder.input` line?

(If I'm doing it wrong I'd appreciate any suggestions as to how to resolve this.)