simple_form 3.0.4 → 3.1.0.rc1
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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -43
- data/MIT-LICENSE +1 -1
- data/README.md +146 -71
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +19 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +83 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form.rb +38 -6
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
- data/lib/simple_form/components/errors.rb +27 -5
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +9 -5
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +92 -59
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +34 -12
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +23 -13
- data/lib/simple_form/inputs/collection_input.rb +32 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +7 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form/wrappers/builder.rb +5 -5
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +5 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/test/action_view_extensions/builder_test.rb +2 -2
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +17 -0
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +51 -32
- data/test/form_builder/general_test.rb +2 -2
- data/test/form_builder/input_field_test.rb +21 -37
- data/test/form_builder/label_test.rb +24 -1
- data/test/form_builder/wrapper_test.rb +67 -0
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +50 -2
- data/test/inputs/collection_check_boxes_input_test.rb +40 -11
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -17
- data/test/inputs/collection_select_input_test.rb +108 -3
- data/test/inputs/datetime_input_test.rb +105 -38
- data/test/inputs/discovery_test.rb +12 -1
- data/test/inputs/grouped_collection_select_input_test.rb +36 -0
- data/test/inputs/string_input_test.rb +20 -0
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +12 -2
- data/test/support/misc_helpers.rb +46 -8
- data/test/support/models.rb +49 -24
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8f1158908d7180ea273c9c3f411d61d58297825
|
4
|
+
data.tar.gz: 33db5d3272ef17c15ad7390b432dcc3b390ae484
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ccf6e4cd2f1c171d4acf02861c78b54ec05bdf3161f2ed32442fe6cc814538ca991b7e5bc0748aa3b3dedfac9a14fd31feed025a95cb48623038463585d2a8e
|
7
|
+
data.tar.gz: df77813f38fe1e70c73be0cc41b88a065030c6d2c998586273e550984d3b342f6604e87acc8e5ef19343c26fb6d87d5ac13a0b84d9d63806aa5e52b8052f0bd1
|
data/CHANGELOG.md
CHANGED
@@ -1,49 +1,38 @@
|
|
1
|
-
## 3.0.
|
2
|
-
|
3
|
-
### bug fix
|
4
|
-
* Fix method reflection for Ruby 2.1+. [@badosu](https://github.com/badosu)
|
5
|
-
* Do not remove HTML attributes if components are not present.
|
6
|
-
|
7
|
-
## 3.0.3
|
8
|
-
|
9
|
-
### bug fix
|
10
|
-
* Fix XSS vulnerability on error components.
|
11
|
-
|
12
|
-
## 3.0.2
|
1
|
+
## 3.1.0.rc1
|
13
2
|
|
14
3
|
### enhancements
|
15
|
-
|
16
|
-
*
|
17
|
-
|
18
|
-
|
4
|
+
* Add support to html markup in the I18n options. [@laurocaetano](https://github.com/laurocaetano)
|
5
|
+
* Add the `full_error` component. [@laurocaetano](https://github.com/laurocaetano)
|
6
|
+
* Add support to `scope` to be used on associations. [@laurocaetano](https://github.com/laurocaetano)
|
7
|
+
* Execute the association `condition` in the object context. [@laurocaetano](https://github.com/laurocaetano)
|
8
|
+
* Check if the given association responds to `order` before calling it. [@laurocaetano](https://github.com/laurocaetano)
|
9
|
+
* Add Bootstrap 3 initializer template.
|
10
|
+
* 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)
|
11
|
+
* `input_field` uses the same wrapper as input but only with attribute components. [@nashby](https://github.com/nashby)
|
12
|
+
* Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc)
|
13
|
+
* 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)
|
14
|
+
* Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)
|
15
|
+
* Map `datetime`, `date` and `time` input types to their respective HTML5 input tags
|
16
|
+
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
|
17
|
+
* Add `boolean_label_class` config.
|
18
|
+
* Add `:html` option to include additional attributes on custom wrappers [@remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
|
19
|
+
* Make possible to use the Wrappers API to define attributes for the components.
|
20
|
+
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
21
|
+
* Put a whitespace before the `inline_label` options of boolean input if it is present.
|
22
|
+
* Add support to configure the `label_text` proc at the wrapper level. [@NOX73](https://github.com/NOX73)
|
23
|
+
* `label_text` proc now receive three arguments (label, request, and if the label was explicit). [@timscott](https://github.com/timscott)
|
24
|
+
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
|
25
|
+
* Add support to define custom error messages for the attributes.
|
26
|
+
* Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
|
19
27
|
|
20
28
|
### bug fix
|
21
|
-
*
|
22
|
-
|
23
|
-
|
29
|
+
* Collection input that uses automatic collection translation properly sets checked values.
|
30
|
+
Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
|
31
|
+
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
32
|
+
* Grouped collection uses the first non-empty object to detect label and value methods.
|
24
33
|
|
25
|
-
|
26
|
-
*
|
27
|
-
|
28
|
-
* Change default `:value_method` of collection tags from `:last` to `:second` [@nashby](https://github.com/nashby)
|
29
|
-
* Support `Proc` object in `:conditions` option of associations [@bradly](https://github.com/bradly)
|
30
|
-
* `input_field` supports `html5` component [@nashby](https://github.com/nashby)
|
31
|
-
* Make `field_error_proc` configurable [@dfens](https://github.com/dfens)
|
32
|
-
* Support to Rails 4.
|
33
|
-
* Removed deprecated methods.
|
34
|
-
* SimpleForm no longer sets the `size` attribute automatically and the `default_input_size` setting
|
35
|
-
is now deprecated.
|
36
|
-
* Support to aria-required attribute to required fields [@ckundo](https://github.com/ckundo)
|
37
|
-
|
38
|
-
### bug fix
|
39
|
-
* Make `DateTimeInput#label_target` method to work with string values in `I18n.t('date.order')` (default
|
40
|
-
behaviour in Rails 4)
|
41
|
-
Closes [#846](https://github.com/plataformatec/simple_form/issues/846) [@mjankowski](https://github.com/mjankowski)
|
42
|
-
* Add "checkbox" class to the label of boolean input when there is no `:label`
|
43
|
-
in `generate_additional_classes_for` config option [@nashby](https://github.com/nashby)
|
44
|
-
* Support models with digits in their names [@webgago](https://github.com/webgago)
|
45
|
-
* Remove deprecation warnings related to `Relation#all` from Rails 4.
|
46
|
-
* Form builder can be used outside the context of a controller [@jasonwebster](https://github.com/jasonwebster)
|
47
|
-
* Skip pattern attribute when using `validates_format_of` with `:without` option [@glebm](https://github.com/glebm)
|
34
|
+
## deprecation
|
35
|
+
* Methods on custom inputs now accept a required argument with the wrapper options.
|
36
|
+
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
48
37
|
|
49
|
-
Please check [
|
38
|
+
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-
|
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
|
-
[](http://badge.fury.io/rb/simple_form)
|
6
|
-
[](http://travis-ci.org/plataformatec/simple_form)
|
7
|
-
[](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.
|
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
|
-
###
|
42
|
+
### Bootstrap
|
47
43
|
|
48
|
-
**Simple Form** can be easily integrated to the [
|
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 [
|
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
|
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
|
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
|
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_wrap_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
|
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
|
-
*
|
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
|
-
*
|
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
|
-
*
|
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
|
-
*
|
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
|
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
|
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
|
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
|
-
|
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
|
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,36 @@ form_for @user do |f|
|
|
471
506
|
end
|
472
507
|
```
|
473
508
|
|
474
|
-
##
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
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
|
+
`text` | `textarea` | `text`
|
525
|
+
`file` | `input[type=file]` | `string` responding to file methods
|
526
|
+
`hidden` | `input[type=hidden]` | -
|
527
|
+
`integer` | `input[type=number]` | `integer`
|
528
|
+
`float` | `input[type=number]` | `float`
|
529
|
+
`decimal` | `input[type=number]` | `decimal`
|
530
|
+
`range` | `input[type=range]` | -
|
531
|
+
`datetime` | `datetime select` | `datetime/timestamp`
|
532
|
+
`date` | `date select` | `date`
|
533
|
+
`time` | `time select` | `time`
|
534
|
+
`select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
|
535
|
+
`radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
|
536
|
+
`check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
|
537
|
+
`country` | `select` (countries as options) | `string` with `name =~ /country/`
|
538
|
+
`time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
|
504
539
|
|
505
540
|
## Custom inputs
|
506
541
|
|
@@ -510,7 +545,7 @@ that extends the string one, you just need to add this file:
|
|
510
545
|
```ruby
|
511
546
|
# app/inputs/currency_input.rb
|
512
547
|
class CurrencyInput < SimpleForm::Inputs::Base
|
513
|
-
def input
|
548
|
+
def input(wrapper_options)
|
514
549
|
"$ #{@builder.text_field(attribute_name, input_html_options)}".html_safe
|
515
550
|
end
|
516
551
|
end
|
@@ -521,6 +556,7 @@ And use it in your views:
|
|
521
556
|
```ruby
|
522
557
|
f.input :money, as: :currency
|
523
558
|
```
|
559
|
+
Note, you may have to create the `app/inputs/` directory and restart your webserver.
|
524
560
|
|
525
561
|
You can also redefine existing **Simple Form** inputs by creating a new class with the same name. For
|
526
562
|
instance, if you want to wrap date/time/datetime in a div, you can do:
|
@@ -528,7 +564,7 @@ instance, if you want to wrap date/time/datetime in a div, you can do:
|
|
528
564
|
```ruby
|
529
565
|
# app/inputs/date_time_input.rb
|
530
566
|
class DateTimeInput < SimpleForm::Inputs::DateTimeInput
|
531
|
-
def input
|
567
|
+
def input(wrapper_options)
|
532
568
|
template.content_tag(:div, super)
|
533
569
|
end
|
534
570
|
end
|
@@ -571,7 +607,7 @@ end
|
|
571
607
|
|
572
608
|
## I18n
|
573
609
|
|
574
|
-
**Simple Form** uses all power of I18n API to lookup labels, hints and placeholders. To customize your
|
610
|
+
**Simple Form** uses all power of I18n API to lookup labels, hints, prompts and placeholders. To customize your
|
575
611
|
forms you can create a locale file like this:
|
576
612
|
|
577
613
|
```yaml
|
@@ -589,12 +625,18 @@ en:
|
|
589
625
|
user:
|
590
626
|
username: 'Your username'
|
591
627
|
password: '****'
|
628
|
+
include_blanks:
|
629
|
+
user:
|
630
|
+
age: 'Rather not say'
|
631
|
+
prompts:
|
632
|
+
gender:
|
633
|
+
age: 'Select your gender'
|
592
634
|
```
|
593
635
|
|
594
636
|
And your forms will use this information to render the components for you.
|
595
637
|
|
596
|
-
**Simple Form** also lets you be more specific, separating lookups through actions
|
597
|
-
|
638
|
+
**Simple Form** also lets you be more specific, separating lookups through actions.
|
639
|
+
Let's say you want a different label for new and edit actions, the locale file would
|
598
640
|
be something like:
|
599
641
|
|
600
642
|
```yaml
|
@@ -633,13 +675,19 @@ en:
|
|
633
675
|
```
|
634
676
|
|
635
677
|
**Simple Form** will always look for a default attribute translation under the "defaults" key if no
|
636
|
-
specific is found inside the model key.
|
637
|
-
the new syntax, just move "labels.#{attribute}" to "labels.defaults.#{attribute}".
|
678
|
+
specific is found inside the model key.
|
638
679
|
|
639
|
-
In addition, **Simple Form** will fallback to default human_attribute_name from Rails when no other
|
680
|
+
In addition, **Simple Form** will fallback to default `human_attribute_name` from Rails when no other
|
640
681
|
translation is found for labels. Finally, you can also overwrite any label, hint or placeholder
|
641
682
|
inside your view, just by passing the option manually. This way the I18n lookup will be skipped.
|
642
683
|
|
684
|
+
For `:prompt` and `:include_blank` the I18n lookup is optional and to enable it is necessary to pass
|
685
|
+
`:translate` as value.
|
686
|
+
|
687
|
+
```ruby
|
688
|
+
f.input :gender, prompt: :translate
|
689
|
+
```
|
690
|
+
|
643
691
|
**Simple Form** also has support for translating options in collection helpers. For instance, given a
|
644
692
|
User with a `:gender` attribute, you might want to create a select box showing translated labels
|
645
693
|
that would post either `male` or `female` as value. With **Simple Form** you could create an input
|
@@ -770,13 +818,23 @@ end
|
|
770
818
|
|
771
819
|
this will wrap the hint and error components within a `div` tag using the class `'separator'`.
|
772
820
|
|
821
|
+
You can customize _Form components_ passing options to them:
|
822
|
+
|
823
|
+
```ruby
|
824
|
+
config.wrappers do |b|
|
825
|
+
b.use :label_input, class: 'label-input-class'
|
826
|
+
end
|
827
|
+
```
|
828
|
+
|
829
|
+
This you set the input and label class to `'label-input-class'`.
|
830
|
+
|
773
831
|
If you want to customize the custom _Form components_ on demand you can give it a name like this:
|
774
832
|
|
775
833
|
```ruby
|
776
834
|
config.wrappers do |b|
|
777
835
|
b.use :placeholder
|
778
836
|
b.use :label_input
|
779
|
-
b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
|
837
|
+
b.wrapper :my_wrapper, tag: :div, class: 'separator', html: { id: 'my_wrapper_id' } do |component|
|
780
838
|
component.use :hint, wrap_with: { tag: :span, class: :hint }
|
781
839
|
component.use :error, wrap_with: { tag: :span, class: :error }
|
782
840
|
end
|
@@ -850,10 +908,25 @@ required attribute to force a value into an input and will prevent form submissi
|
|
850
908
|
Depending on the design of the application this may or may not be desired. In many cases it can
|
851
909
|
break existing UI's.
|
852
910
|
|
853
|
-
It is possible to disable all HTML 5 extensions in **Simple Form**
|
911
|
+
It is possible to disable all HTML 5 extensions in **Simple Form** removing the `html5` component
|
912
|
+
from the wrapper used to render the inputs.
|
913
|
+
|
914
|
+
For example, change:
|
915
|
+
|
916
|
+
```ruby
|
917
|
+
config.wrappers tag: :div do |b|
|
918
|
+
b.use :html5
|
919
|
+
|
920
|
+
b.use :label_input
|
921
|
+
end
|
922
|
+
```
|
923
|
+
|
924
|
+
To:
|
854
925
|
|
855
926
|
```ruby
|
856
|
-
|
927
|
+
config.wrappers tag: :div do |b|
|
928
|
+
b.use :label_input
|
929
|
+
end
|
857
930
|
```
|
858
931
|
|
859
932
|
If you want to have all other HTML 5 features, such as the new field types, you can disable only
|
@@ -870,7 +943,7 @@ help you to use some generic javascript validation.
|
|
870
943
|
You can also add `novalidate` to a specific form by setting the option on the form itself:
|
871
944
|
|
872
945
|
```erb
|
873
|
-
<%= simple_form_for(resource, html: {novalidate: true}) do |form| %>
|
946
|
+
<%= simple_form_for(resource, html: { novalidate: true }) do |form| %>
|
874
947
|
```
|
875
948
|
|
876
949
|
Please notice that any of the configurations above will not disable the `placeholder` component,
|
@@ -894,9 +967,6 @@ You can view the **Simple Form** documentation in RDoc format here:
|
|
894
967
|
|
895
968
|
http://rubydoc.info/github/plataformatec/simple_form/master/frames
|
896
969
|
|
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
970
|
### Bug reports
|
901
971
|
|
902
972
|
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as
|
@@ -912,9 +982,14 @@ https://github.com/plataformatec/simple_form/issues
|
|
912
982
|
* Rafael Mendonça França (https://github.com/rafaelfranca)
|
913
983
|
* Vasiliy Ermolovich (https://github.com/nashby)
|
914
984
|
|
985
|
+
[](http://badge.fury.io/rb/simple_form)
|
986
|
+
[](http://travis-ci.org/plataformatec/simple_form)
|
987
|
+
[](https://codeclimate.com/github/plataformatec/simple_form)
|
988
|
+
[](http://inch-pages.github.io/github/plataformatec/simple_form)
|
989
|
+
|
915
990
|
## License
|
916
991
|
|
917
|
-
MIT License. Copyright 2009-
|
992
|
+
MIT License. Copyright 2009-2014 Plataformatec. http://plataformatec.com.br
|
918
993
|
|
919
994
|
You are not granted rights or licenses to the trademarks of the Plataformatec, including without
|
920
995
|
limitation the Simple Form name or logo.
|