Merge pull request #941 from plataformatec/ek-doc-boolean-style

Add to REAME some doc to boolean_style
This commit is contained in:
Erich Kist 2013-12-10 12:39:45 -08:00
commit 987083511b
3 changed files with 41 additions and 1 deletions

View File

@ -248,9 +248,41 @@ Example:
```ruby
simple_form_for @user do |f|
f.input_field :name
f.input_field :remember_me, as: :boolean
end
```
```html
<form>
...
<input class="string required" id="user_name" maxlength="255" name="user[name]" size="255" type="text">
<input name="user[remember_me]" type="hidden" value="0">
<label class="checkbox">
<input class="boolean optional" id="user_published" name="user[remember_me]" type="checkbox" value="1">
</label>
</form>
```
For check boxes and radio buttons you can remove the label changing `boolean_style` from defaul value `:nested` to `:inline`.
Example:
```ruby
simple_form_for @user do |f|
f.input_field :name
f.input_field :remember_me, as: :boolean, boolean_style: :inline
end
```
```html
<form>
...
<input class="string required" id="user_name" maxlength="255" name="user[name]" size="255" type="text">
<input name="user[remember_me]" type="hidden" value="0">
<input class="boolean optional" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
</form>
```
Produces:
```html

View File

@ -132,7 +132,7 @@ module SimpleForm
#
def input_field(attribute_name, options={})
options = options.dup
options[:input_html] = options.except(:as, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
options = @defaults.deep_dup.deep_merge(options) if @defaults
input = find_input(attribute_name, options)

View File

@ -138,4 +138,12 @@ class InputFieldTest < ActionView::TestCase
assert_no_select 'select.status[label_method]'
assert_no_select 'select.status[value_method]'
end
test 'build input_field does not treat "boolean_style" as an HTML attribute' do
with_concat_form_for(@user) do |f|
f.input_field :active, boolean_style: :nested
end
assert_no_select 'input.boolean[boolean_style]'
end
end