README.md in simple_form-2.1.2 vs README.md in simple_form-2.1.3
- old
+ new
@@ -33,27 +33,27 @@
```ruby
gem 'country_select'
```
-### Twitter Bootstrap
+### Bootstrap
-**SimpleForm** 2.0 can be easily integrated to the [Twitter Bootstrap](http://twitter.github.com/bootstrap).
+**Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/2.3.2/) 2.3.
To do that you have to use the `bootstrap` option in the install generator, like this:
```console
rails generate simple_form:install --bootstrap
```
-You have to be sure that you added a copy of the [Twitter Bootstrap](http://twitter.github.com/bootstrap)
+You have to be sure that you added a copy of the [Bootstrap](http://getbootstrap.com/2.3.2/)
assets on your application.
For more information see the generator output, our
[example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
[the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
-**NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 or higher.
+**NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 up to 2.3.
### Zurb Foundation 3
To generate wrappers that are compatible with [Zurb Foundation 3](http://foundation.zurb.com/), pass the `foundation` option to the generator, like this:
@@ -161,10 +161,17 @@
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
```
+By default, SimpleForm will look at the column type in the database and use an
+appropriate input for the column. For example, a column created with type
+`:text` in the database will use a `textarea` input by default. See the section
+[Available input types and defaults for each column
+type](https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type)
+for a complete list of defaults.
+
**SimpleForm** also lets you overwrite the default input type it creates:
```erb
<%= simple_form_for @user do |f| %>
<%= f.input :username %>
@@ -174,11 +181,11 @@
<%= f.button :submit %>
<% end %>
```
So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
-labels and a text area instead of a text field for the description. You can also render boolean
+labels and a textarea instead of a text field for the description. You can also render boolean
attributes using `:as => :select` to show a dropdown.
It is also possible to give the `:disabled` option to **SimpleForm**, and it'll automatically mark
the wrapper as disabled with a css class, so you can style labels, hints and other components inside
the wrapper as well:
@@ -287,11 +294,11 @@
f.input :shipping_country, :priority => [ "Brazil" ], :collection => [ "Australia", "Brazil", "New Zealand"]
```
### Associations
-To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or check boxes.
+To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or checkboxes.
Lets see how it works: imagine you have a user model that belongs to a company and has_and_belongs_to_many
roles. The structure would be something like:
```ruby
class User < ActiveRecord::Base
@@ -319,11 +326,11 @@
<% end %>
```
Simple enough, right? This is going to render a `:select` input for choosing the `:company`, and another
`:select` input with `:multiple` option for the `:roles`. You can, of course, change it to use radio
-buttons and check boxes as well:
+buttons and checkboxes as well:
```ruby
f.association :company, :as => :radio_buttons
f.association :roles, :as => :check_boxes
```
@@ -406,11 +413,11 @@
<label class="collection_radio_buttons" for="user_options_false">No</label>
```
#### Collection Check Boxes
-Creates a collection of check boxes with labels associated (same API as `collection_select`):
+Creates a collection of checkboxes with labels associated (same API as `collection_select`):
```ruby
form_for @user do |f|
f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end
@@ -431,41 +438,41 @@
form_for @user do |f|
f.collection_check_boxes :role_ids, Role.all, :id, :name # using :roles here is not going to work.
end
```
-## Mappings/Inputs available
+## Available input types and defaults for each column type
-**SimpleForm** comes with a lot of default mappings:
+The following table shows the html element you will get for each attribute
+according to its database definition. These defaults can be changed by
+specifying the helper method in the column `Mapping` as the `as:` option.
-```text
-Mapping Input Column Type
+ Mapping | Generated HTML Element | Database Column Type
+ --------------- |:-------------------------------------|:--------------------
+ `boolean` | `input[type=checkbox]` | `boolean`
+ `string` | `input[type=text]` | `string`
+ `email` | `input[type=email]` | `string` with `name =~ /email/`
+ `url` | `input[type=url]` | `string` with `name =~ /url/`
+ `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
+ `password` | `input[type=password]` | `string` with `name =~ /password/`
+ `search` | `input[type=search]` | -
+ `text` | `textarea` | `text`
+ `file` | `input[type=file]` | `string` responding to file methods
+ `hidden` | `input[type=hidden]` | -
+ `integer` | `input[type=number]` | `integer`
+ `float` | `input[type=number]` | `float`
+ `decimal` | `input[type=number]` | `decimal`
+ `range` | `input[type=range]` | -
+ `datetime` | `select` | `datetime/timestamp`
+ `date` | `select` | `date`
+ `time` | `select` | `time`
+ `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
+ `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
+ `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
+ `country` | `select` (countries as options) | `string` with `name =~ /country/`
+ `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
-boolean check box boolean
-string text field string
-email email field string with name matching "email"
-url url field string with name matching "url"
-tel tel field string with name matching "phone"
-password password field string with name matching "password"
-search search -
-text text area text
-file file field string, responding to file methods
-hidden hidden field -
-integer number field integer
-float number field float
-decimal number field decimal
-range range field -
-datetime datetime select datetime/timestamp
-date date select date
-time time select time
-select collection select belongs_to/has_many/has_and_belongs_to_many associations
-radio_buttons collection radio buttons belongs_to
-check_boxes collection check boxes has_many/has_and_belongs_to_many associations
-country country select string with name matching "country"
-time_zone time zone select string with name matching "time_zone"
-```
-
## Custom inputs
It is very easy to add custom inputs to **SimpleForm**. For instance, if you want to add a custom input
that extends the string one, you just need to add this file:
@@ -481,9 +488,10 @@
And use it in your views:
```ruby
f.input :money, :as => :currency
```
+Note, you may have to create the `app/inputs/` directory and restart your webserver.
You can also redefine existing **SimpleForm** inputs by creating a new class with the same name. For
instance, if you want to wrap date/time/datetime in a div, you can do:
```ruby