simple_form 3.0.2 → 3.1.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -32
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +179 -73
  5. data/lib/generators/simple_form/install_generator.rb +2 -2
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +25 -5
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +108 -24
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
  10. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
  12. data/lib/simple_form/components/errors.rb +30 -2
  13. data/lib/simple_form/components/hints.rb +2 -2
  14. data/lib/simple_form/components/html5.rb +1 -1
  15. data/lib/simple_form/components/label_input.rb +20 -2
  16. data/lib/simple_form/components/labels.rb +10 -6
  17. data/lib/simple_form/components/maxlength.rb +1 -1
  18. data/lib/simple_form/components/min_max.rb +1 -1
  19. data/lib/simple_form/components/pattern.rb +1 -1
  20. data/lib/simple_form/components/placeholders.rb +2 -2
  21. data/lib/simple_form/components/readonly.rb +1 -1
  22. data/lib/simple_form/form_builder.rb +121 -72
  23. data/lib/simple_form/helpers.rb +5 -5
  24. data/lib/simple_form/inputs/base.rb +33 -11
  25. data/lib/simple_form/inputs/block_input.rb +1 -1
  26. data/lib/simple_form/inputs/boolean_input.rb +27 -14
  27. data/lib/simple_form/inputs/collection_input.rb +32 -9
  28. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
  29. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  30. data/lib/simple_form/inputs/date_time_input.rb +12 -2
  31. data/lib/simple_form/inputs/file_input.rb +4 -2
  32. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  33. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  34. data/lib/simple_form/inputs/numeric_input.rb +5 -4
  35. data/lib/simple_form/inputs/password_input.rb +4 -2
  36. data/lib/simple_form/inputs/priority_input.rb +4 -2
  37. data/lib/simple_form/inputs/range_input.rb +1 -1
  38. data/lib/simple_form/inputs/string_input.rb +4 -2
  39. data/lib/simple_form/inputs/text_input.rb +4 -2
  40. data/lib/simple_form/railtie.rb +7 -0
  41. data/lib/simple_form/tags.rb +8 -0
  42. data/lib/simple_form/version.rb +1 -1
  43. data/lib/simple_form/wrappers/builder.rb +6 -6
  44. data/lib/simple_form/wrappers/leaf.rb +28 -0
  45. data/lib/simple_form/wrappers/many.rb +6 -6
  46. data/lib/simple_form/wrappers/root.rb +1 -1
  47. data/lib/simple_form/wrappers/single.rb +5 -3
  48. data/lib/simple_form/wrappers.rb +1 -0
  49. data/lib/simple_form.rb +46 -6
  50. data/test/action_view_extensions/builder_test.rb +5 -5
  51. data/test/action_view_extensions/form_helper_test.rb +13 -13
  52. data/test/components/label_test.rb +36 -36
  53. data/test/form_builder/association_test.rb +21 -4
  54. data/test/form_builder/button_test.rb +5 -5
  55. data/test/form_builder/error_notification_test.rb +1 -1
  56. data/test/form_builder/error_test.rb +78 -17
  57. data/test/form_builder/general_test.rb +65 -60
  58. data/test/form_builder/hint_test.rb +15 -15
  59. data/test/form_builder/input_field_test.rb +37 -13
  60. data/test/form_builder/label_test.rb +44 -12
  61. data/test/form_builder/wrapper_test.rb +120 -19
  62. data/test/generators/simple_form_generator_test.rb +2 -2
  63. data/test/inputs/boolean_input_test.rb +54 -6
  64. data/test/inputs/collection_check_boxes_input_test.rb +63 -17
  65. data/test/inputs/collection_radio_buttons_input_test.rb +112 -36
  66. data/test/inputs/collection_select_input_test.rb +141 -36
  67. data/test/inputs/datetime_input_test.rb +116 -49
  68. data/test/inputs/disabled_test.rb +15 -15
  69. data/test/inputs/discovery_test.rb +56 -6
  70. data/test/inputs/file_input_test.rb +2 -2
  71. data/test/inputs/general_test.rb +20 -20
  72. data/test/inputs/grouped_collection_select_input_test.rb +38 -2
  73. data/test/inputs/hidden_input_test.rb +4 -4
  74. data/test/inputs/numeric_input_test.rb +24 -24
  75. data/test/inputs/priority_input_test.rb +7 -7
  76. data/test/inputs/readonly_test.rb +19 -19
  77. data/test/inputs/required_test.rb +13 -13
  78. data/test/inputs/string_input_test.rb +41 -21
  79. data/test/inputs/text_input_test.rb +4 -4
  80. data/test/simple_form_test.rb +8 -0
  81. data/test/support/discovery_inputs.rb +32 -2
  82. data/test/support/misc_helpers.rb +71 -5
  83. data/test/support/models.rb +50 -24
  84. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0b1424f33f30519ecda1b748031fdbd3a3a5ac8
4
- data.tar.gz: aebd1dbf4c0537ed49040cd5641a892f116b2bc8
3
+ metadata.gz: 88d85494e222c13d302bed66c947ebc999702a46
4
+ data.tar.gz: 6974cf74dc9cada33d515c0125c4506262aa4118
5
5
  SHA512:
6
- metadata.gz: 94c159b4f89974808ddd180935003b32f9023beb9e32878a5c0fdfbd82ef88f3d14f4efc5d748a13f8ce05b3490f05c7ce36002cd9b343486929b214281f811b
7
- data.tar.gz: f003707ac3883c392678b6423cb7912668e18b37473a2c4425cfd2a3e9f4f94e0173152f5bc00aa5aade4dad17b4975960b171e49e157c68a1c4a649307aa8f0
6
+ metadata.gz: c2f1599b149fd691ccc0471af01e5f2f997465f55449bfea0924768c45f83510d36911342e54e8c42dfa75adf5da278261188f17c938b3571446b97c419e2011
7
+ data.tar.gz: 4c1677e4c36aa1381a378ef3a2c688db1881089d014cb97078f14dd2f5000a618fddc9671f78663fd693c86e4bc8524f3f2c9837aa5e8f7707c9b07b223cf114
data/CHANGELOG.md CHANGED
@@ -1,38 +1,41 @@
1
- ## 3.0.2
1
+ ## 3.1.0.rc2
2
2
 
3
3
  ### enhancements
4
-
5
- * Support Rails 4.1
6
-
7
- ## 3.0.1
4
+ * Add mapping to `uuid` columns.
5
+ * Add custom namespaces for custom inputs feature. [@vala](https://github.com/vala)
6
+ * Add `:unless_blank` option to the wrapper API. [@IanVaughan](https://github.com/IanVaughan)
7
+ * Add support to html markup in the I18n options. [@laurocaetano](https://github.com/laurocaetano)
8
+ * Add the `full_error` component. [@laurocaetano](https://github.com/laurocaetano)
9
+ * Add support to `scope` to be used on associations. [@laurocaetano](https://github.com/laurocaetano)
10
+ * Execute the association `condition` in the object context. [@laurocaetano](https://github.com/laurocaetano)
11
+ * Check if the given association responds to `order` before calling it. [@laurocaetano](https://github.com/laurocaetano)
12
+ * Add Bootstrap 3 initializer template.
13
+ * For radio or checkbox collection always use `:item_wrapper_tag` to wrap the content and add `label` when using `boolean_style` with `:nested` [@kassio](https://github.com/kassio) and [@erichkist](https://github.com/erichkist)
14
+ * `input_field` uses the same wrapper as input but only with attribute components. [@nashby](https://github.com/nashby)
15
+ * Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc)
16
+ * Add `for` attribute to `label` when collections are rendered as radio or checkbox [@erichkist](https://github.com/erichkist), [@ulissesalmeida](https://github.com/ulissesalmeida) and [@fabioyamate](https://github.com/fabioyamate)
17
+ * Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)
18
+ * Map `datetime`, `date` and `time` input types to their respective HTML5 input tags
19
+ when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
20
+ * Add `boolean_label_class` config.
21
+ * Add `:html` option to include additional attributes on custom wrappers [@remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
22
+ * Make possible to use the Wrappers API to define attributes for the components.
23
+ See https://github.com/plataformatec/simple_form/pull/997 for more information.
24
+ * Put a whitespace before the `inline_label` options of boolean input if it is present.
25
+ * Add support to configure the `label_text` proc at the wrapper level. [@NOX73](https://github.com/NOX73)
26
+ * `label_text` proc now receive three arguments (label, request, and if the label was explicit). [@timscott](https://github.com/timscott)
27
+ * Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
28
+ * Add support to define custom error messages for the attributes.
29
+ * Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
8
30
 
9
31
  ### bug fix
10
- * Fix XSS vulnerability on label, hint and error components.
11
-
12
- ## 3.0.0
32
+ * Collection input that uses automatic collection translation properly sets checked values.
33
+ Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
34
+ * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
35
+ * Grouped collection uses the first non-empty object to detect label and value methods.
13
36
 
14
- ### enhancements
15
- * New `input_class` global config option to set a class to be generated in all inputs.
16
- * Collection tags accept html attributes as the last element of collection [@nashby](https://github.com/nashby)
17
- * Change default `:value_method` of collection tags from `:last` to `:second` [@nashby](https://github.com/nashby)
18
- * Support `Proc` object in `:conditions` option of associations [@bradly](https://github.com/bradly)
19
- * `input_field` supports `html5` component [@nashby](https://github.com/nashby)
20
- * Make `field_error_proc` configurable [@dfens](https://github.com/dfens)
21
- * Support to Rails 4.
22
- * Removed deprecated methods.
23
- * SimpleForm no longer sets the `size` attribute automatically and the `default_input_size` setting
24
- is now deprecated.
25
- * Support to aria-required attribute to required fields [@ckundo](https://github.com/ckundo)
26
-
27
- ### bug fix
28
- * Make `DateTimeInput#label_target` method to work with string values in `I18n.t('date.order')` (default
29
- behaviour in Rails 4)
30
- Closes [#846](https://github.com/plataformatec/simple_form/issues/846) [@mjankowski](https://github.com/mjankowski)
31
- * Add "checkbox" class to the label of boolean input when there is no `:label`
32
- in `generate_additional_classes_for` config option [@nashby](https://github.com/nashby)
33
- * Support models with digits in their names [@webgago](https://github.com/webgago)
34
- * Remove deprecation warnings related to `Relation#all` from Rails 4.
35
- * Form builder can be used outside the context of a controller [@jasonwebster](https://github.com/jasonwebster)
36
- * Skip pattern attribute when using `validates_format_of` with `:without` option [@glebm](https://github.com/glebm)
37
+ ## deprecation
38
+ * Methods on custom inputs now accept a required argument with the wrapper options.
39
+ See https://github.com/plataformatec/simple_form/pull/997 for more information.
37
40
 
38
- Please check [v2.1](https://github.com/plataformatec/simple_form/blob/v2.1/CHANGELOG.md) for previous changes.
41
+ Please check [v3.0](https://github.com/plataformatec/simple_form/blob/v3.0/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2009-2014 Plataformatec http://plataformatec.com.br/
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,10 +2,6 @@
2
2
 
3
3
  By [Plataformatec](http://plataformatec.com.br/).
4
4
 
5
- [![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
6
- [![Build Status](https://api.travis-ci.org/plataformatec/simple_form.png?branch=master)](http://travis-ci.org/plataformatec/simple_form)
7
- [![Code Climate](https://codeclimate.com/github/plataformatec/simple_form.png)](https://codeclimate.com/github/plataformatec/simple_form)
8
-
9
5
  Rails forms made easy.
10
6
 
11
7
  **Simple Form** aims to be as flexible as possible while helping you with powerful components to create
@@ -14,7 +10,7 @@ you find the better design for your eyes. Most of the DSL was inherited from For
14
10
  which we are thankful for and should make you feel right at home.
15
11
 
16
12
  INFO: This README is [also available in a friendly navigable format](http://simple-form.plataformatec.com.br/)
17
- and refers to **Simple Form** 3.0. For older releases, check the related branch for your version.
13
+ and refers to **Simple Form** 3.1. For older releases, check the related branch for your version.
18
14
 
19
15
  ## Installation
20
16
 
@@ -43,24 +39,22 @@ Also, if you want to use the country select, you will need the
43
39
  gem 'country_select'
44
40
  ```
45
41
 
46
- ### Twitter Bootstrap
42
+ ### Bootstrap
47
43
 
48
- **Simple Form** can be easily integrated to the [Twitter Bootstrap](http://twitter.github.com/bootstrap).
44
+ **Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/).
49
45
  To do that you have to use the `bootstrap` option in the install generator, like this:
50
46
 
51
47
  ```console
52
48
  rails generate simple_form:install --bootstrap
53
49
  ```
54
50
 
55
- You have to be sure that you added a copy of the [Twitter Bootstrap](http://twitter.github.com/bootstrap)
51
+ You have to be sure that you added a copy of the [Bootstrap](http://getbootstrap.com/)
56
52
  assets on your application.
57
53
 
58
54
  For more information see the generator output, our
59
55
  [example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
60
56
  [the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
61
57
 
62
- **NOTE**: **Simple Form** integration requires Twitter Bootstrap version 2.0 or higher.
63
-
64
58
  ### Zurb Foundation 3
65
59
 
66
60
  To generate wrappers that are compatible with [Zurb Foundation 3](http://foundation.zurb.com/), pass
@@ -81,7 +75,7 @@ Please see the [instructions on how to install Foundation in a Rails app](http:/
81
75
  **Simple Form** was designed to be customized as you need to. Basically it's a stack of components that
82
76
  are invoked to create a complete html input for you, which by default contains label, hints, errors
83
77
  and the input itself. It does not aim to create a lot of different logic from the default Rails
84
- form helpers, as they do a great work by themselves. Instead, **Simple Form** acts as a DSL and just
78
+ form helpers, as they do a great job by themselves. Instead, **Simple Form** acts as a DSL and just
85
79
  maps your input type (retrieved from the column definition in the database) to a specific helper method.
86
80
 
87
81
  To start using **Simple Form** you just have to use the helper it provides:
@@ -176,6 +170,13 @@ And of course, the `required` property of any input can be overwritten as needed
176
170
  <% end %>
177
171
  ```
178
172
 
173
+ By default, **Simple Form** will look at the column type in the database and use an
174
+ appropriate input for the column. For example, a column created with type
175
+ `:text` in the database will use a `textarea` input by default. See the section
176
+ [Available input types and defaults for each column
177
+ type](https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type)
178
+ for a complete list of defaults.
179
+
179
180
  **Simple Form** also lets you overwrite the default input type it creates:
180
181
 
181
182
  ```erb
@@ -189,11 +190,11 @@ And of course, the `required` property of any input can be overwritten as needed
189
190
  ```
190
191
 
191
192
  So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
192
- labels and a text area instead of a text field for the description. You can also render boolean
193
+ labels and a textarea instead of a text field for the description. You can also render boolean
193
194
  attributes using `as: :select` to show a dropdown.
194
195
 
195
196
  It is also possible to give the `:disabled` option to **Simple Form**, and it'll automatically mark
196
- the wrapper as disabled with a css class, so you can style labels, hints and other components inside
197
+ the wrapper as disabled with a CSS class, so you can style labels, hints and other components inside
197
198
  the wrapper as well:
198
199
 
199
200
  ```erb
@@ -210,6 +211,7 @@ the wrapper as well:
210
211
  <%= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
211
212
  end_year: Date.today.year - 12, discard_day: true,
212
213
  order: [:month, :year] %>
214
+ <%= f.input :accepts, as: :boolean, checked_value: true, unchecked_value: false %>
213
215
  <%= f.button :submit %>
214
216
  <% end %>
215
217
  ```
@@ -241,9 +243,42 @@ Example:
241
243
  ```ruby
242
244
  simple_form_for @user do |f|
243
245
  f.input_field :name
246
+ f.input_field :remember_me, as: :boolean
247
+ end
248
+ ```
249
+
250
+ ```html
251
+ <form>
252
+ ...
253
+ <input class="string required" id="user_name" maxlength="255" name="user[name]" size="255" type="text">
254
+ <input name="user[remember_me]" type="hidden" value="0">
255
+ <label class="checkbox">
256
+ <input class="boolean optional" id="user_published" name="user[remember_me]" type="checkbox" value="1">
257
+ </label>
258
+ </form>
259
+ ```
260
+
261
+ For check boxes and radio buttons you can remove the label changing `boolean_style` from default value `:nested` to `:inline`.
262
+ Also, `item_wrapper_tag` will not work when `boolean_style` is set to `:nested`.
263
+
264
+ Example:
265
+
266
+ ```ruby
267
+ simple_form_for @user do |f|
268
+ f.input_field :name
269
+ f.input_field :remember_me, as: :boolean, boolean_style: :inline
244
270
  end
245
271
  ```
246
272
 
273
+ ```html
274
+ <form>
275
+ ...
276
+ <input class="string required" id="user_name" maxlength="255" name="user[name]" size="255" type="text">
277
+ <input name="user[remember_me]" type="hidden" value="0">
278
+ <input class="boolean optional" id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
279
+ </form>
280
+ ```
281
+
247
282
  Produces:
248
283
 
249
284
  ```html
@@ -269,14 +304,14 @@ overriding the `:collection` option:
269
304
  Collections can be arrays or ranges, and when a `:collection` is given the `:select` input will be
270
305
  rendered by default, so we don't need to pass the `as: :select` option. Other types of collection
271
306
  are `:radio_buttons` and `:check_boxes`. Those are added by **Simple Form** to Rails set of form
272
- helpers (read Extra Helpers session below for more information).
307
+ helpers (read Extra Helpers section below for more information).
273
308
 
274
309
  Collection inputs accept two other options beside collections:
275
310
 
276
- * _label_method_ => the label method to be applied to the collection to retrieve the label (use this
311
+ * *label_method* => the label method to be applied to the collection to retrieve the label (use this
277
312
  instead of the `text_method` option in `collection_select`)
278
313
 
279
- * _value_method_ => the value method to be applied to the collection to retrieve the value
314
+ * *value_method* => the value method to be applied to the collection to retrieve the value
280
315
 
281
316
  Those methods are useful to manipulate the given collection. Both of these options also accept
282
317
  lambda/procs in case you want to calculate the value or label in a special way eg. custom
@@ -296,24 +331,24 @@ f.input :country_id, collection: @continents, as: :grouped_select, group_method:
296
331
  Grouped collection inputs accept the same `:label_method` and `:value_method` options, which will be
297
332
  used to retrieve label/value attributes for the `option` tags. Besides that, you can give:
298
333
 
299
- * _group_method_ => the method to be called on the given collection to generate the options for
334
+ * *group_method* => the method to be called on the given collection to generate the options for
300
335
  each group (required)
301
336
 
302
- * _group_label_method_ => the label method to be applied on the given collection to retrieve the label
337
+ * *group_label_method* => the label method to be applied on the given collection to retrieve the label
303
338
  for the _optgroup_ (**Simple Form** will attempt to guess the best one the same way it does with
304
339
  `:label_method`)
305
340
 
306
341
  ### Priority
307
342
 
308
343
  **Simple Form** also supports `:time_zone` and `:country`. When using such helpers, you can give
309
- `:priority` as option to select which time zones and/or countries should be given higher priority:
344
+ `:priority` as an option to select which time zones and/or countries should be given higher priority:
310
345
 
311
346
  ```ruby
312
347
  f.input :residence_country, priority: [ "Brazil" ]
313
348
  f.input :time_zone, priority: /US/
314
349
  ```
315
350
 
316
- Those values can also be configured with a default value to be used site use through the
351
+ Those values can also be configured with a default value to be used on the site through the
317
352
  `SimpleForm.country_priority` and `SimpleForm.time_zone_priority` helpers.
318
353
 
319
354
  Note: While using `country_select` if you want to restrict to only a subset of countries for a specific
@@ -325,8 +360,8 @@ f.input :shipping_country, priority: [ "Brazil" ], collection: [ "Australia", "B
325
360
 
326
361
  ### Associations
327
362
 
328
- To deal with associations, **Simple Form** can generate select inputs, a series of radios buttons or check boxes.
329
- Lets see how it works: imagine you have a user model that belongs to a company and has_and_belongs_to_many
363
+ To deal with associations, **Simple Form** can generate select inputs, a series of radios buttons or checkboxes.
364
+ Lets see how it works: imagine you have a user model that belongs to a company and `has_and_belongs_to_many`
330
365
  roles. The structure would be something like:
331
366
 
332
367
  ```ruby
@@ -357,7 +392,7 @@ Now we have the user form:
357
392
 
358
393
  Simple enough, right? This is going to render a `:select` input for choosing the `:company`, and another
359
394
  `:select` input with `:multiple` option for the `:roles`. You can, of course, change it to use radio
360
- buttons and check boxes as well:
395
+ buttons and checkboxes as well:
361
396
 
362
397
  ```ruby
363
398
  f.association :company, as: :radio_buttons
@@ -420,7 +455,7 @@ Rails helper, but change the builder to use the `SimpleForm::FormBuilder`.
420
455
 
421
456
  ```ruby
422
457
  form_for @user do |f|
423
- f.simple_fields_for :posts do |posts_form|
458
+ simple_fields_for :posts do |posts_form|
424
459
  # Here you have all simple_form methods available
425
460
  posts_form.input :title
426
461
  end
@@ -446,7 +481,7 @@ end
446
481
 
447
482
  #### Collection Check Boxes
448
483
 
449
- Creates a collection of check boxes with labels associated (same API as `collection_select`):
484
+ Creates a collection of checkboxes with labels associated (same API as `collection_select`):
450
485
 
451
486
  ```ruby
452
487
  form_for @user do |f|
@@ -471,36 +506,37 @@ form_for @user do |f|
471
506
  end
472
507
  ```
473
508
 
474
- ## Mappings/Inputs available
475
-
476
- **Simple Form** comes with a lot of default mappings:
477
-
478
- ```text
479
- Mapping Input Column Type
480
-
481
- boolean check box boolean
482
- string text field string
483
- email email field string with name matching "email"
484
- url url field string with name matching "url"
485
- tel tel field string with name matching "phone"
486
- password password field string with name matching "password"
487
- search search -
488
- text text area text
489
- file file field string, responding to file methods
490
- hidden hidden field -
491
- integer number field integer
492
- float number field float
493
- decimal number field decimal
494
- range range field -
495
- datetime datetime select datetime/timestamp
496
- date date select date
497
- time time select time
498
- select collection select belongs_to/has_many/has_and_belongs_to_many associations
499
- radio_buttons collection radio buttons belongs_to
500
- check_boxes collection check boxes has_many/has_and_belongs_to_many associations
501
- country country select string with name matching "country"
502
- time_zone time zone select string with name matching "time_zone"
503
- ```
509
+ ## Available input types and defaults for each column type
510
+
511
+ The following table shows the html element you will get for each attribute
512
+ according to its database definition. These defaults can be changed by
513
+ specifying the helper method in the column `Mapping` as the `as:` option.
514
+
515
+ Mapping | Generated HTML Element | Database Column Type
516
+ --------------- |:-------------------------------------|:--------------------
517
+ `boolean` | `input[type=checkbox]` | `boolean`
518
+ `string` | `input[type=text]` | `string`
519
+ `email` | `input[type=email]` | `string` with `name =~ /email/`
520
+ `url` | `input[type=url]` | `string` with `name =~ /url/`
521
+ `tel` | `input[type=tel]` | `string` with `name =~ /phone/`
522
+ `password` | `input[type=password]` | `string` with `name =~ /password/`
523
+ `search` | `input[type=search]` | -
524
+ `uuid` | `input[type=text]` | `uuid`
525
+ `text` | `textarea` | `text`
526
+ `file` | `input[type=file]` | `string` responding to file methods
527
+ `hidden` | `input[type=hidden]` | -
528
+ `integer` | `input[type=number]` | `integer`
529
+ `float` | `input[type=number]` | `float`
530
+ `decimal` | `input[type=number]` | `decimal`
531
+ `range` | `input[type=range]` | -
532
+ `datetime` | `datetime select` | `datetime/timestamp`
533
+ `date` | `date select` | `date`
534
+ `time` | `time select` | `time`
535
+ `select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
536
+ `radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
537
+ `check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
538
+ `country` | `select` (countries as options) | `string` with `name =~ /country/`
539
+ `time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
504
540
 
505
541
  ## Custom inputs
506
542
 
@@ -510,7 +546,7 @@ that extends the string one, you just need to add this file:
510
546
  ```ruby
511
547
  # app/inputs/currency_input.rb
512
548
  class CurrencyInput < SimpleForm::Inputs::Base
513
- def input
549
+ def input(wrapper_options)
514
550
  "$ #{@builder.text_field(attribute_name, input_html_options)}".html_safe
515
551
  end
516
552
  end
@@ -521,6 +557,7 @@ And use it in your views:
521
557
  ```ruby
522
558
  f.input :money, as: :currency
523
559
  ```
560
+ Note, you may have to create the `app/inputs/` directory and restart your webserver.
524
561
 
525
562
  You can also redefine existing **Simple Form** inputs by creating a new class with the same name. For
526
563
  instance, if you want to wrap date/time/datetime in a div, you can do:
@@ -528,7 +565,7 @@ instance, if you want to wrap date/time/datetime in a div, you can do:
528
565
  ```ruby
529
566
  # app/inputs/date_time_input.rb
530
567
  class DateTimeInput < SimpleForm::Inputs::DateTimeInput
531
- def input
568
+ def input(wrapper_options)
532
569
  template.content_tag(:div, super)
533
570
  end
534
571
  end
@@ -545,6 +582,28 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
545
582
  end
546
583
  ```
547
584
 
585
+ If needed, you can namespace your custom inputs in a module and tell **Simple Form** to look for
586
+ their definitions in this module. This can avoid conflicts with other form libraries (like Formtastic) that look up
587
+ the global context to find inputs definition too.
588
+
589
+ ```ruby
590
+ # app/inputs/custom_inputs/numeric_input
591
+ module CustomInputs
592
+ class NumericInput < SimpleForm::Inputs::NumericInput
593
+ def input_html_classes
594
+ super.push('no-spinner')
595
+ end
596
+ end
597
+ end
598
+ ```
599
+
600
+ And in the **SimpleForm** initializer :
601
+
602
+ ```ruby
603
+ # config/simple_form.rb
604
+ config.custom_inputs_namespaces << "CustomInputs"
605
+ ```
606
+
548
607
  ## Custom form builder
549
608
 
550
609
  You can create a custom form builder that uses **Simple Form**.
@@ -563,15 +622,14 @@ Create a form builder class that inherits from `SimpleForm::FormBuilder`.
563
622
  ```ruby
564
623
  class CustomFormBuilder < SimpleForm::FormBuilder
565
624
  def input(attribute_name, options = {}, &block)
566
- options[:input_html].merge! class: 'custom'
567
- super
625
+ super(attribute_name, options.merge(label: false), &block)
568
626
  end
569
627
  end
570
628
  ```
571
629
 
572
630
  ## I18n
573
631
 
574
- **Simple Form** uses all power of I18n API to lookup labels, hints and placeholders. To customize your
632
+ **Simple Form** uses all power of I18n API to lookup labels, hints, prompts and placeholders. To customize your
575
633
  forms you can create a locale file like this:
576
634
 
577
635
  ```yaml
@@ -589,12 +647,18 @@ en:
589
647
  user:
590
648
  username: 'Your username'
591
649
  password: '****'
650
+ include_blanks:
651
+ user:
652
+ age: 'Rather not say'
653
+ prompts:
654
+ user:
655
+ gender: 'Select your gender'
592
656
  ```
593
657
 
594
658
  And your forms will use this information to render the components for you.
595
659
 
596
- **Simple Form** also lets you be more specific, separating lookups through actions for labels, hints and
597
- placeholders. Let's say you want a different label for new and edit actions, the locale file would
660
+ **Simple Form** also lets you be more specific, separating lookups through actions.
661
+ Let's say you want a different label for new and edit actions, the locale file would
598
662
  be something like:
599
663
 
600
664
  ```yaml
@@ -633,13 +697,19 @@ en:
633
697
  ```
634
698
 
635
699
  **Simple Form** will always look for a default attribute translation under the "defaults" key if no
636
- specific is found inside the model key. Note that this syntax is different from 1.x. To migrate to
637
- the new syntax, just move "labels.#{attribute}" to "labels.defaults.#{attribute}".
700
+ specific is found inside the model key.
638
701
 
639
- In addition, **Simple Form** will fallback to default human_attribute_name from Rails when no other
702
+ In addition, **Simple Form** will fallback to default `human_attribute_name` from Rails when no other
640
703
  translation is found for labels. Finally, you can also overwrite any label, hint or placeholder
641
704
  inside your view, just by passing the option manually. This way the I18n lookup will be skipped.
642
705
 
706
+ For `:prompt` and `:include_blank` the I18n lookup is optional and to enable it is necessary to pass
707
+ `:translate` as value.
708
+
709
+ ```ruby
710
+ f.input :gender, prompt: :translate
711
+ ```
712
+
643
713
  **Simple Form** also has support for translating options in collection helpers. For instance, given a
644
714
  User with a `:gender` attribute, you might want to create a select box showing translated labels
645
715
  that would post either `male` or `female` as value. With **Simple Form** you could create an input
@@ -770,13 +840,23 @@ end
770
840
 
771
841
  this will wrap the hint and error components within a `div` tag using the class `'separator'`.
772
842
 
843
+ You can customize _Form components_ passing options to them:
844
+
845
+ ```ruby
846
+ config.wrappers do |b|
847
+ b.use :label_input, class: 'label-input-class'
848
+ end
849
+ ```
850
+
851
+ This you set the input and label class to `'label-input-class'`.
852
+
773
853
  If you want to customize the custom _Form components_ on demand you can give it a name like this:
774
854
 
775
855
  ```ruby
776
856
  config.wrappers do |b|
777
857
  b.use :placeholder
778
858
  b.use :label_input
779
- b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
859
+ b.wrapper :my_wrapper, tag: :div, class: 'separator', html: { id: 'my_wrapper_id' } do |component|
780
860
  component.use :hint, wrap_with: { tag: :span, class: :hint }
781
861
  component.use :error, wrap_with: { tag: :span, class: :error }
782
862
  end
@@ -838,6 +918,15 @@ end
838
918
  By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
839
919
  The same for placeholder.
840
920
 
921
+ It is also possible to give the option `:unless_blank` to the wrapper if you want to render it only
922
+ when the content is present.
923
+
924
+ ```ruby
925
+ b.wrapper tag: :span, class: 'hint', unless_blank: true do |component|
926
+ component.optional :hint
927
+ end
928
+ ```
929
+
841
930
  ## HTML 5 Notice
842
931
 
843
932
  By default, **Simple Form** will generate input field types and attributes that are supported in HTML5,
@@ -850,10 +939,25 @@ required attribute to force a value into an input and will prevent form submissi
850
939
  Depending on the design of the application this may or may not be desired. In many cases it can
851
940
  break existing UI's.
852
941
 
853
- It is possible to disable all HTML 5 extensions in **Simple Form** with the following configuration:
942
+ It is possible to disable all HTML 5 extensions in **Simple Form** removing the `html5` component
943
+ from the wrapper used to render the inputs.
944
+
945
+ For example, change:
946
+
947
+ ```ruby
948
+ config.wrappers tag: :div do |b|
949
+ b.use :html5
950
+
951
+ b.use :label_input
952
+ end
953
+ ```
954
+
955
+ To:
854
956
 
855
957
  ```ruby
856
- SimpleForm.html5 = false # default is true
958
+ config.wrappers tag: :div do |b|
959
+ b.use :label_input
960
+ end
857
961
  ```
858
962
 
859
963
  If you want to have all other HTML 5 features, such as the new field types, you can disable only
@@ -870,7 +974,7 @@ help you to use some generic javascript validation.
870
974
  You can also add `novalidate` to a specific form by setting the option on the form itself:
871
975
 
872
976
  ```erb
873
- <%= simple_form_for(resource, html: {novalidate: true}) do |form| %>
977
+ <%= simple_form_for(resource, html: { novalidate: true }) do |form| %>
874
978
  ```
875
979
 
876
980
  Please notice that any of the configurations above will not disable the `placeholder` component,
@@ -894,9 +998,6 @@ You can view the **Simple Form** documentation in RDoc format here:
894
998
 
895
999
  http://rubydoc.info/github/plataformatec/simple_form/master/frames
896
1000
 
897
- If you need to use **Simple Form** with Rails 2.3, you can always run `gem server` from the command line
898
- after you install the gem to access the old documentation.
899
-
900
1001
  ### Bug reports
901
1002
 
902
1003
  If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
@@ -912,9 +1013,14 @@ https://github.com/plataformatec/simple_form/issues
912
1013
  * Rafael Mendonça França (https://github.com/rafaelfranca)
913
1014
  * Vasiliy Ermolovich (https://github.com/nashby)
914
1015
 
1016
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/simple_form.png)](http://badge.fury.io/rb/simple_form)
1017
+ [![Build Status](https://api.travis-ci.org/plataformatec/simple_form.svg?branch=master)](http://travis-ci.org/plataformatec/simple_form)
1018
+ [![Code Climate](https://codeclimate.com/github/plataformatec/simple_form.png)](https://codeclimate.com/github/plataformatec/simple_form)
1019
+ [![Inline docs](http://inch-ci.org/github/plataformatec/simple_form.png)](http://inch-ci.org/github/plataformatec/simple_form)
1020
+
915
1021
  ## License
916
1022
 
917
- MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br
1023
+ MIT License. Copyright 2009-2014 Plataformatec. http://plataformatec.com.br
918
1024
 
919
1025
  You are not granted rights or licenses to the trademarks of the Plataformatec, including without
920
1026
  limitation the Simple Form name or logo.
@@ -4,12 +4,12 @@ module SimpleForm
4
4
  desc "Copy SimpleForm default files"
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
  class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
7
- class_option :bootstrap, type: :boolean, desc: 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
7
+ class_option :bootstrap, type: :boolean, desc: 'Add the Bootstrap wrappers to the SimpleForm initializer.'
8
8
  class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
9
9
 
10
10
  def info_bootstrap
11
11
  return if options.bootstrap? || options.foundation?
12
- puts "SimpleForm 2 supports Twitter Bootstrap and Zurb Foundation 3. If you want "\
12
+ puts "SimpleForm 2 supports Bootstrap and Zurb Foundation 3. If you want "\
13
13
  "a configuration that is compatible with one of these frameworks, then please " \
14
14
  "re-run this generator with --bootstrap or --foundation as an option."
15
15
  end
@@ -1,12 +1,11 @@
1
1
  ===============================================================================
2
2
 
3
3
  Be sure to have a copy of the Bootstrap stylesheet available on your
4
- application, you can get it on http://twitter.github.com/bootstrap.
4
+ application, you can get it on http://getbootstrap.com/.
5
5
 
6
6
  Inside your views, use the 'simple_form_for' with one of the Bootstrap form
7
- classes, '.form-horizontal', '.form-inline', '.form-search' or
8
- '.form-vertical', as the following:
7
+ classes, '.form-horizontal' or '.form-inline', as the following:
9
8
 
10
- = simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|
9
+ = simple_form_for(@user, html: { class: 'form-horizontal' }) do |form|
11
10
 
12
11
  ===============================================================================