simple_form 2.1.0 → 3.0.0.rc
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +15 -32
- data/README.md +103 -71
- data/lib/generators/simple_form/install_generator.rb +3 -3
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +13 -13
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +14 -14
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +3 -3
- data/lib/simple_form/action_view_extensions/builder.rb +1 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +2 -9
- data/lib/simple_form/components/html5.rb +5 -2
- data/lib/simple_form/components/labels.rb +3 -3
- data/lib/simple_form/components/maxlength.rb +1 -8
- data/lib/simple_form/components/pattern.rb +2 -2
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +147 -49
- data/lib/simple_form/helpers.rb +1 -1
- data/lib/simple_form/inputs/base.rb +2 -6
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +5 -4
- data/lib/simple_form/inputs/collection_input.rb +6 -6
- data/lib/simple_form/inputs/numeric_input.rb +0 -6
- data/lib/simple_form/inputs/password_input.rb +0 -1
- data/lib/simple_form/inputs/string_input.rb +0 -1
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +61 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -29
- data/lib/simple_form/wrappers/many.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers.rb +1 -1
- data/lib/simple_form.rb +39 -47
- data/test/action_view_extensions/builder_test.rb +75 -88
- data/test/action_view_extensions/form_helper_test.rb +25 -16
- data/test/components/label_test.rb +46 -46
- data/test/form_builder/association_test.rb +39 -29
- data/test/form_builder/button_test.rb +4 -4
- data/test/form_builder/error_notification_test.rb +8 -8
- data/test/form_builder/error_test.rb +12 -12
- data/test/form_builder/general_test.rb +58 -52
- data/test/form_builder/hint_test.rb +22 -22
- data/test/form_builder/input_field_test.rb +12 -12
- data/test/form_builder/label_test.rb +6 -6
- data/test/form_builder/wrapper_test.rb +21 -21
- data/test/inputs/boolean_input_test.rb +23 -23
- data/test/inputs/collection_check_boxes_input_test.rb +61 -55
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -79
- data/test/inputs/collection_select_input_test.rb +70 -45
- data/test/inputs/datetime_input_test.rb +17 -11
- data/test/inputs/disabled_test.rb +10 -10
- data/test/inputs/discovery_test.rb +4 -4
- data/test/inputs/file_input_test.rb +1 -1
- data/test/inputs/general_test.rb +12 -12
- data/test/inputs/grouped_collection_select_input_test.rb +20 -20
- data/test/inputs/hidden_input_test.rb +3 -2
- data/test/inputs/numeric_input_test.rb +3 -3
- data/test/inputs/priority_input_test.rb +9 -3
- data/test/inputs/readonly_test.rb +12 -12
- data/test/inputs/required_test.rb +5 -5
- data/test/inputs/string_input_test.rb +15 -25
- data/test/inputs/text_input_test.rb +1 -1
- data/test/support/misc_helpers.rb +46 -24
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +62 -61
- data/test/test_helper.rb +20 -24
- metadata +32 -33
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: eebdc48d53472ed80e668fd6c2fa30ebf30695a1
|
|
4
|
+
data.tar.gz: 368a258b70c60fcb73ed568a21f357b39c1fa93f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fd1c37c0fffa1d3f3b5a06d19790f37a6aec133ab9d98d792c0c60ba40ea64628085ef8f26ab8f44a50bb17af3b0ee3e8dfdcd6d2997dfea021bc41240c300ed
|
|
7
|
+
data.tar.gz: ee7024a3684a698d0267fd2469723bfca7775270f064b0e11680cc85891c8d6d235189bd608d636fc551c7d3726b3d8167577ebc49869bc8c6969254c7ee5d00
|
data/CHANGELOG.md
CHANGED
|
@@ -1,37 +1,20 @@
|
|
|
1
|
-
##
|
|
1
|
+
## master
|
|
2
2
|
|
|
3
3
|
### enhancements
|
|
4
|
-
* `
|
|
5
|
-
as `:min_max`, `:maxlength`, `:placeholder`, `:pattern`, `:readonly`.
|
|
6
|
-
Closes[#362](https://github.com/plataformatec/simple_form/issues/632).
|
|
7
|
-
([@nashby](https://github.com/nashby))
|
|
8
|
-
* support for Rails eager loading.
|
|
9
|
-
Closes [#478](https://github.com/plataformatec/simple_form/issues/478).
|
|
10
|
-
* generate required attribute for `date_time` input.
|
|
11
|
-
([@nashby](https://github.com/nashby))
|
|
12
|
-
Closes [#730](https://github.com/plataformatec/simple_form/issues/730).
|
|
13
|
-
* `grouped_collection_select` now accepts proc/lambda as label and value method.
|
|
14
|
-
([@svendahlstrand](https://github.com/svendahlstrand))
|
|
15
|
-
Closes [#623](https://github.com/plataformatec/simple_form/issues/623).
|
|
16
|
-
* Add Zurb Foundation 3 integration.
|
|
17
|
-
([@balexand](https://github.com/balexand))
|
|
18
|
-
* Generates additional wrapper class based on object + attribute name.
|
|
19
|
-
([@lucasmazza](https://github.com/lucasmazza))
|
|
20
|
-
Closes [#576](https://github.com/plataformatec/simple_form/issues/576).
|
|
21
|
-
* Allow `input_field` to work with `:defaults` options.
|
|
22
|
-
([@smidwap](https://github.com/smidwap))
|
|
4
|
+
* Make `field_error_proc` configurable [@dfens](https://github.com/dfens)
|
|
23
5
|
|
|
24
6
|
### bug fix
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
given false. This checks for the option in `#has_hint?`, avoiding the lookup
|
|
29
|
-
in such cases. This issues has been caught with #627, thanks to
|
|
30
|
-
([@shwoodard](https://github.com/shwoodard)).
|
|
31
|
-
* Fix default I18n lookup for association input.
|
|
32
|
-
([@nashby](https://github.com/nashby))
|
|
33
|
-
Closes [#679](https://github.com/plataformatec/simple_form/issues/679).
|
|
34
|
-
* Fix escaping issue in `label_input` component
|
|
35
|
-
([@allomov](https://github.com/allomov))
|
|
7
|
+
* Remove deprecation warnings related to `Relation#all` from Rails 4.
|
|
8
|
+
* Form builder can be used outside the context of a controller [@jasonwebster](https://github.com/jasonwebster)
|
|
9
|
+
* Skip pattern attribute when using `validates_format_of` with `:without` option [@glebm](https://github.com/glebm)
|
|
36
10
|
|
|
37
|
-
|
|
11
|
+
## 3.0.0.beta1
|
|
12
|
+
|
|
13
|
+
### enhancements
|
|
14
|
+
* Support to Rails 4.
|
|
15
|
+
* Removed deprecated methods.
|
|
16
|
+
* SimpleForm no longer sets the `size` attribute automatically and the `default_input_size` setting
|
|
17
|
+
is now deprecated.
|
|
18
|
+
* Support to aria-required attribute to required fields [@ckundo](https://github.com/ckundo)
|
|
19
|
+
|
|
20
|
+
Please check [v2.1](https://github.com/plataformatec/simple_form/blob/v2.1/CHANGELOG.md) for previous changes.
|
data/README.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
By [Plataformatec](http://plataformatec.com.br/).
|
|
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
|
+
Rails forms made easy.
|
|
3
10
|
|
|
4
11
|
**SimpleForm** aims to be as flexible as possible while helping you with powerful components to create
|
|
5
12
|
your forms. The basic goal of SimpleForm is to not touch your way of defining the layout, letting
|
|
6
13
|
you find the better design for your eyes. Most of the DSL was inherited from Formtastic,
|
|
7
14
|
which we are thankful for and should make you feel right at home.
|
|
8
15
|
|
|
9
|
-
INFO: This README
|
|
16
|
+
INFO: This README is [also available in a friendly navigable format](http://simple-form.plataformatec.com.br/)
|
|
17
|
+
and refers to **SimpleForm** 3.0. For older releases, check the related branch for your version.
|
|
10
18
|
|
|
11
19
|
## Installation
|
|
12
20
|
|
|
@@ -37,7 +45,7 @@ gem 'country_select'
|
|
|
37
45
|
|
|
38
46
|
### Twitter Bootstrap
|
|
39
47
|
|
|
40
|
-
**SimpleForm**
|
|
48
|
+
**SimpleForm** can be easily integrated to the [Twitter Bootstrap](http://twitter.github.com/bootstrap).
|
|
41
49
|
To do that you have to use the `bootstrap` option in the install generator, like this:
|
|
42
50
|
|
|
43
51
|
```console
|
|
@@ -63,7 +71,7 @@ rails generate simple_form:install --foundation
|
|
|
63
71
|
|
|
64
72
|
Please note that the Foundation wrapper does not support the `:hint` option by default. In order to enable hints, please uncomment the appropriate line in `config/initializers/simple_form_foundation.rb`. You will need to provide your own CSS styles for hints.
|
|
65
73
|
|
|
66
|
-
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/rails.php).
|
|
74
|
+
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/old-docs/f3/rails.php).
|
|
67
75
|
|
|
68
76
|
## Usage
|
|
69
77
|
|
|
@@ -91,10 +99,10 @@ even a placeholder. For boolean inputs, you can add an inline label as well:
|
|
|
91
99
|
|
|
92
100
|
```erb
|
|
93
101
|
<%= simple_form_for @user do |f| %>
|
|
94
|
-
<%= f.input :username, :
|
|
95
|
-
<%= f.input :password, :
|
|
96
|
-
<%= f.input :email, :
|
|
97
|
-
<%= f.input :remember_me, :
|
|
102
|
+
<%= f.input :username, label: 'Your username please' %>
|
|
103
|
+
<%= f.input :password, hint: 'No special characters.' %>
|
|
104
|
+
<%= f.input :email, placeholder: 'user@domain.com' %>
|
|
105
|
+
<%= f.input :remember_me, inline_label: 'Yes, remember me' %>
|
|
98
106
|
<%= f.button :submit %>
|
|
99
107
|
<% end %>
|
|
100
108
|
```
|
|
@@ -104,9 +112,9 @@ of any of them:
|
|
|
104
112
|
|
|
105
113
|
```erb
|
|
106
114
|
<%= simple_form_for @user do |f| %>
|
|
107
|
-
<%= f.input :username, :
|
|
108
|
-
<%= f.input :password, :
|
|
109
|
-
<%= f.input :password_confirmation, :
|
|
115
|
+
<%= f.input :username, label_html: { class: 'my_class' } %>
|
|
116
|
+
<%= f.input :password, hint: false, error_html: { id: 'password_error'} %>
|
|
117
|
+
<%= f.input :password_confirmation, label: false %>
|
|
110
118
|
<%= f.button :submit %>
|
|
111
119
|
<% end %>
|
|
112
120
|
```
|
|
@@ -116,9 +124,9 @@ option, for instance:
|
|
|
116
124
|
|
|
117
125
|
```erb
|
|
118
126
|
<%= simple_form_for @user do |f| %>
|
|
119
|
-
<%= f.input :username, :
|
|
120
|
-
<%= f.input :password, :
|
|
121
|
-
<%= f.input :remember_me, :
|
|
127
|
+
<%= f.input :username, input_html: { class: 'special' } %>
|
|
128
|
+
<%= f.input :password, input_html: { maxlength: 20 } %>
|
|
129
|
+
<%= f.input :remember_me, input_html: { value: '1' } %>
|
|
122
130
|
<%= f.button :submit %>
|
|
123
131
|
<% end %>
|
|
124
132
|
```
|
|
@@ -128,10 +136,10 @@ you can use the `:defaults` option in `simple_form_for`. Specific options in `in
|
|
|
128
136
|
overwrite the defaults:
|
|
129
137
|
|
|
130
138
|
```erb
|
|
131
|
-
<%= simple_form_for @user, :
|
|
132
|
-
<%= f.input :username, :
|
|
133
|
-
<%= f.input :password, :
|
|
134
|
-
<%= f.input :remember_me, :
|
|
139
|
+
<%= simple_form_for @user, defaults: { input_html: { class: 'default_class' } } do |f| %>
|
|
140
|
+
<%= f.input :username, input_html: { class: 'special' } %>
|
|
141
|
+
<%= f.input :password, input_html: { maxlength: 20 } %>
|
|
142
|
+
<%= f.input :remember_me, input_html: { value: '1' } %>
|
|
135
143
|
<%= f.button :submit %>
|
|
136
144
|
<% end %>
|
|
137
145
|
```
|
|
@@ -141,9 +149,9 @@ any html attribute to that wrapper as well using the `:wrapper_html` option, lik
|
|
|
141
149
|
|
|
142
150
|
```erb
|
|
143
151
|
<%= simple_form_for @user do |f| %>
|
|
144
|
-
<%= f.input :username, :
|
|
145
|
-
<%= f.input :password, :
|
|
146
|
-
<%= f.input :remember_me, :
|
|
152
|
+
<%= f.input :username, wrapper_html: { class: 'username' } %>
|
|
153
|
+
<%= f.input :password, wrapper_html: { id: 'password' } %>
|
|
154
|
+
<%= f.input :remember_me, wrapper_html: { class: 'options' } %>
|
|
147
155
|
<%= f.button :submit %>
|
|
148
156
|
<% end %>
|
|
149
157
|
```
|
|
@@ -156,7 +164,7 @@ And of course, the `required` property of any input can be overwritten as needed
|
|
|
156
164
|
|
|
157
165
|
```erb
|
|
158
166
|
<%= simple_form_for @user do |f| %>
|
|
159
|
-
<%= f.input :name, :
|
|
167
|
+
<%= f.input :name, required: false %>
|
|
160
168
|
<%= f.input :username %>
|
|
161
169
|
<%= f.input :password %>
|
|
162
170
|
<%= f.button :submit %>
|
|
@@ -169,15 +177,15 @@ And of course, the `required` property of any input can be overwritten as needed
|
|
|
169
177
|
<%= simple_form_for @user do |f| %>
|
|
170
178
|
<%= f.input :username %>
|
|
171
179
|
<%= f.input :password %>
|
|
172
|
-
<%= f.input :description, :
|
|
173
|
-
<%= f.input :accepts, :
|
|
180
|
+
<%= f.input :description, as: :text %>
|
|
181
|
+
<%= f.input :accepts, as: :radio_buttons %>
|
|
174
182
|
<%= f.button :submit %>
|
|
175
183
|
<% end %>
|
|
176
184
|
```
|
|
177
185
|
|
|
178
186
|
So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
|
|
179
187
|
labels and a text area instead of a text field for the description. You can also render boolean
|
|
180
|
-
attributes using
|
|
188
|
+
attributes using `as: :select` to show a dropdown.
|
|
181
189
|
|
|
182
190
|
It is also possible to give the `:disabled` option to **SimpleForm**, and it'll automatically mark
|
|
183
191
|
the wrapper as disabled with a css class, so you can style labels, hints and other components inside
|
|
@@ -185,7 +193,7 @@ the wrapper as well:
|
|
|
185
193
|
|
|
186
194
|
```erb
|
|
187
195
|
<%= simple_form_for @user do |f| %>
|
|
188
|
-
<%= f.input :username, :
|
|
196
|
+
<%= f.input :username, disabled: true, hint: 'You cannot change your username.' %>
|
|
189
197
|
<%= f.button :submit %>
|
|
190
198
|
<% end %>
|
|
191
199
|
```
|
|
@@ -194,9 +202,9 @@ the wrapper as well:
|
|
|
194
202
|
|
|
195
203
|
```erb
|
|
196
204
|
<%= simple_form_for @user do |f| %>
|
|
197
|
-
<%= f.input :date_of_birth, :
|
|
198
|
-
:
|
|
199
|
-
:
|
|
205
|
+
<%= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
|
|
206
|
+
end_year: Date.today.year - 12, discard_day: true,
|
|
207
|
+
order: [:month, :year] %>
|
|
200
208
|
<%= f.button :submit %>
|
|
201
209
|
<% end %>
|
|
202
210
|
```
|
|
@@ -209,7 +217,7 @@ the wrapper as well:
|
|
|
209
217
|
<%= f.label :username %>
|
|
210
218
|
<%= f.input_field :username %>
|
|
211
219
|
<%= f.hint 'No special characters, please!' %>
|
|
212
|
-
<%= f.error :username, :
|
|
220
|
+
<%= f.error :username, id: 'user_name_error' %>
|
|
213
221
|
<%= f.full_error :token %>
|
|
214
222
|
<%= f.submit 'Save' %>
|
|
215
223
|
<% end %>
|
|
@@ -217,6 +225,28 @@ the wrapper as well:
|
|
|
217
225
|
|
|
218
226
|
Any extra option passed to these methods will be rendered as html option.
|
|
219
227
|
|
|
228
|
+
### Stripping away all wrapper divs
|
|
229
|
+
|
|
230
|
+
**SimpleForm** also allows you to strip away all the div wrappers around the `<input>` field that is generated with the usual `f.input`.
|
|
231
|
+
The easiest way to achieve this is to use `f.input_field`.
|
|
232
|
+
|
|
233
|
+
Example:
|
|
234
|
+
|
|
235
|
+
```erb
|
|
236
|
+
simple_form_for @user do |f|
|
|
237
|
+
f.input_field :name
|
|
238
|
+
end
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Produces:
|
|
242
|
+
|
|
243
|
+
```erb
|
|
244
|
+
<input class="string required" id="user_name" maxlength="100"
|
|
245
|
+
name="user[name]" size="100" type="text" value="Carlos" />
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
To view the actual RDocs for this, check them out here - http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:input_field
|
|
249
|
+
|
|
220
250
|
### Collections
|
|
221
251
|
|
|
222
252
|
And what if you want to create a select containing the age from 18 to 60 in your form? You can do it
|
|
@@ -225,13 +255,13 @@ overriding the `:collection` option:
|
|
|
225
255
|
```erb
|
|
226
256
|
<%= simple_form_for @user do |f| %>
|
|
227
257
|
<%= f.input :user %>
|
|
228
|
-
<%= f.input :age, :
|
|
258
|
+
<%= f.input :age, collection: 18..60 %>
|
|
229
259
|
<%= f.button :submit %>
|
|
230
260
|
<% end %>
|
|
231
261
|
```
|
|
232
262
|
|
|
233
263
|
Collections can be arrays or ranges, and when a `:collection` is given the `:select` input will be
|
|
234
|
-
rendered by default, so we don't need to pass the
|
|
264
|
+
rendered by default, so we don't need to pass the `as: :select` option. Other types of collection
|
|
235
265
|
are `:radio_buttons` and `:check_boxes`. Those are added by **SimpleForm** to Rails set of form
|
|
236
266
|
helpers (read Extra Helpers session below for more information).
|
|
237
267
|
|
|
@@ -248,13 +278,13 @@ translation. All other options given are sent straight to the underlying helper.
|
|
|
248
278
|
can give prompt as:
|
|
249
279
|
|
|
250
280
|
```ruby
|
|
251
|
-
f.input :age, :
|
|
281
|
+
f.input :age, collection: 18..60, prompt: "Select your age"
|
|
252
282
|
```
|
|
253
283
|
|
|
254
284
|
It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
|
|
255
285
|
|
|
256
286
|
```ruby
|
|
257
|
-
f.input :country_id, :
|
|
287
|
+
f.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries
|
|
258
288
|
```
|
|
259
289
|
|
|
260
290
|
Grouped collection inputs accept the same `:label_method` and `:value_method` options, which will be
|
|
@@ -273,8 +303,8 @@ used to retrieve label/value attributes for the `option` tags. Besides that, you
|
|
|
273
303
|
`:priority` as option to select which time zones and/or countries should be given higher priority:
|
|
274
304
|
|
|
275
305
|
```ruby
|
|
276
|
-
f.input :residence_country, :
|
|
277
|
-
f.input :time_zone, :
|
|
306
|
+
f.input :residence_country, priority: [ "Brazil" ]
|
|
307
|
+
f.input :time_zone, priority: /US/
|
|
278
308
|
```
|
|
279
309
|
|
|
280
310
|
Those values can also be configured with a default value to be used site use through the
|
|
@@ -284,7 +314,7 @@ Note: While using `country_select` if you want to restrict to only a subset of c
|
|
|
284
314
|
drop down then you may use the `:collection` option:
|
|
285
315
|
|
|
286
316
|
```ruby
|
|
287
|
-
f.input :shipping_country, :
|
|
317
|
+
f.input :shipping_country, priority: [ "Brazil" ], collection: [ "Australia", "Brazil", "New Zealand"]
|
|
288
318
|
```
|
|
289
319
|
|
|
290
320
|
### Associations
|
|
@@ -324,8 +354,8 @@ Simple enough, right? This is going to render a `:select` input for choosing the
|
|
|
324
354
|
buttons and check boxes as well:
|
|
325
355
|
|
|
326
356
|
```ruby
|
|
327
|
-
f.association :company, :
|
|
328
|
-
f.association :roles, :
|
|
357
|
+
f.association :company, as: :radio_buttons
|
|
358
|
+
f.association :roles, as: :check_boxes
|
|
329
359
|
```
|
|
330
360
|
|
|
331
361
|
The association helper just invokes `input` under the hood, so all options available to `:select`,
|
|
@@ -333,13 +363,13 @@ The association helper just invokes `input` under the hood, so all options avail
|
|
|
333
363
|
the collection by hand, all together with the prompt:
|
|
334
364
|
|
|
335
365
|
```ruby
|
|
336
|
-
f.association :company, :
|
|
366
|
+
f.association :company, collection: Company.active.all(order: 'name'), prompt: "Choose a Company"
|
|
337
367
|
```
|
|
338
368
|
|
|
339
369
|
In case you want to declare different labels and values:
|
|
340
370
|
|
|
341
371
|
```ruby
|
|
342
|
-
f.association :company, :
|
|
372
|
+
f.association :company, label_method: :company_name, value_method: :id, include_blank: false
|
|
343
373
|
```
|
|
344
374
|
|
|
345
375
|
### Buttons
|
|
@@ -362,7 +392,7 @@ calling input with a block like so:
|
|
|
362
392
|
|
|
363
393
|
```erb
|
|
364
394
|
<%= f.input :role do %>
|
|
365
|
-
<%= f.select :role, Role.all.map { |r| [r.name, r.id, { :
|
|
395
|
+
<%= f.select :role, Role.all.map { |r| [r.name, r.id, { class: r.company.id }] }, include_blank: true %>
|
|
366
396
|
<% end %>
|
|
367
397
|
```
|
|
368
398
|
|
|
@@ -481,7 +511,7 @@ end
|
|
|
481
511
|
And use it in your views:
|
|
482
512
|
|
|
483
513
|
```ruby
|
|
484
|
-
f.input :money, :
|
|
514
|
+
f.input :money, as: :currency
|
|
485
515
|
```
|
|
486
516
|
|
|
487
517
|
You can also redefine existing **SimpleForm** inputs by creating a new class with the same name. For
|
|
@@ -516,7 +546,7 @@ Create a helper method that calls `simple_form_for` with a custom builder:
|
|
|
516
546
|
```ruby
|
|
517
547
|
def custom_form_for(object, *args, &block)
|
|
518
548
|
options = args.extract_options!
|
|
519
|
-
simple_form_for(object, *(args << options.merge(:
|
|
549
|
+
simple_form_for(object, *(args << options.merge(builder: CustomFormBuilder)), &block)
|
|
520
550
|
end
|
|
521
551
|
```
|
|
522
552
|
|
|
@@ -525,7 +555,7 @@ Create a form builder class that inherits from `SimpleForm::FormBuilder`.
|
|
|
525
555
|
```ruby
|
|
526
556
|
class CustomFormBuilder < SimpleForm::FormBuilder
|
|
527
557
|
def input(attribute_name, options = {}, &block)
|
|
528
|
-
options[:input_html].merge! :
|
|
558
|
+
options[:input_html].merge! class: 'custom'
|
|
529
559
|
super
|
|
530
560
|
end
|
|
531
561
|
end
|
|
@@ -608,7 +638,7 @@ that would post either `male` or `female` as value. With **SimpleForm** you coul
|
|
|
608
638
|
like this:
|
|
609
639
|
|
|
610
640
|
```ruby
|
|
611
|
-
f.input :gender, :
|
|
641
|
+
f.input :gender, collection: [:male, :female]
|
|
612
642
|
```
|
|
613
643
|
|
|
614
644
|
And **SimpleForm** will try a lookup like this in your locale file, to find the right labels to show:
|
|
@@ -670,7 +700,7 @@ en:
|
|
|
670
700
|
This difference exists because **SimpleForm** relies on `object_name` provided by Rails'
|
|
671
701
|
FormBuilder to determine the translation path for a given object instead of `i18n_key` from the
|
|
672
702
|
object itself. Thus, similarly, if a form for an `Admin::User` object is defined by calling
|
|
673
|
-
`simple_form_for @admin_user, :
|
|
703
|
+
`simple_form_for @admin_user, as: :some_user`, **SimpleForm** will look for translations
|
|
674
704
|
under `some_user` instead of `admin_user`.
|
|
675
705
|
|
|
676
706
|
## Configuration
|
|
@@ -686,8 +716,8 @@ With **SimpleForm** you can configure how your components will be rendered using
|
|
|
686
716
|
The syntax looks like this:
|
|
687
717
|
|
|
688
718
|
```ruby
|
|
689
|
-
config.wrappers :
|
|
690
|
-
:
|
|
719
|
+
config.wrappers tag: :div, class: :input,
|
|
720
|
+
error_class: :field_with_errors do |b|
|
|
691
721
|
|
|
692
722
|
# Form extensions
|
|
693
723
|
b.use :html5
|
|
@@ -698,8 +728,8 @@ config.wrappers :tag => :div, :class => :input,
|
|
|
698
728
|
|
|
699
729
|
# Form components
|
|
700
730
|
b.use :label_input
|
|
701
|
-
b.use :hint, :
|
|
702
|
-
b.use :error, :
|
|
731
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
732
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
|
703
733
|
end
|
|
704
734
|
```
|
|
705
735
|
|
|
@@ -722,9 +752,9 @@ You can create new _Form components_ using the wrappers API as in the following
|
|
|
722
752
|
config.wrappers do |b|
|
|
723
753
|
b.use :placeholder
|
|
724
754
|
b.use :label_input
|
|
725
|
-
b.wrapper :
|
|
726
|
-
component.use :hint, :
|
|
727
|
-
component.use :error, :
|
|
755
|
+
b.wrapper tag: :div, class: 'separator' do |component|
|
|
756
|
+
component.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
757
|
+
component.use :error, wrap_with: { tag: :span, class: :error }
|
|
728
758
|
end
|
|
729
759
|
end
|
|
730
760
|
```
|
|
@@ -737,9 +767,9 @@ If you want to customize the custom _Form components_ on demand you can give it
|
|
|
737
767
|
config.wrappers do |b|
|
|
738
768
|
b.use :placeholder
|
|
739
769
|
b.use :label_input
|
|
740
|
-
b.wrapper :my_wrapper, :
|
|
741
|
-
component.use :hint, :
|
|
742
|
-
component.use :error, :
|
|
770
|
+
b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
|
|
771
|
+
component.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
772
|
+
component.use :error, wrap_with: { tag: :span, class: :error }
|
|
743
773
|
end
|
|
744
774
|
end
|
|
745
775
|
```
|
|
@@ -748,13 +778,13 @@ and now you can pass options to your `input` calls to customize the `:my_wrapper
|
|
|
748
778
|
|
|
749
779
|
```ruby
|
|
750
780
|
# Completely turns off the custom wrapper
|
|
751
|
-
f.input :name, :
|
|
781
|
+
f.input :name, my_wrapper: false
|
|
752
782
|
|
|
753
783
|
# Configure the html
|
|
754
|
-
f.input :name, :
|
|
784
|
+
f.input :name, my_wrapper_html: { id: 'special_id' }
|
|
755
785
|
|
|
756
786
|
# Configure the tag
|
|
757
|
-
f.input :name, :
|
|
787
|
+
f.input :name, my_wrapper_tag: :p
|
|
758
788
|
```
|
|
759
789
|
|
|
760
790
|
You can also define more than one wrapper and pick one to render in a specific form or input.
|
|
@@ -771,33 +801,33 @@ and use it in this way:
|
|
|
771
801
|
|
|
772
802
|
```ruby
|
|
773
803
|
# Specifying to whole form
|
|
774
|
-
simple_form_for @user, :
|
|
804
|
+
simple_form_for @user, wrapper: :small do |f|
|
|
775
805
|
f.input :name
|
|
776
806
|
end
|
|
777
807
|
|
|
778
808
|
# Specifying to one input
|
|
779
809
|
simple_form_for @user do |f|
|
|
780
|
-
f.input :name, :
|
|
810
|
+
f.input :name, wrapper: :small
|
|
781
811
|
end
|
|
782
812
|
```
|
|
783
813
|
|
|
784
814
|
**SimpleForm** also allows you to use optional elements. For instance, let's suppose you want to use
|
|
785
815
|
hints or placeholders, but you don't want them to be generated automatically. You can set their
|
|
786
|
-
default values to `false` or use the `optional` method. Is
|
|
816
|
+
default values to `false` or use the `optional` method. Is preferable to use the `optional` syntax:
|
|
787
817
|
|
|
788
818
|
```ruby
|
|
789
|
-
config.wrappers :
|
|
819
|
+
config.wrappers placeholder: false do |b|
|
|
790
820
|
b.use :placeholder
|
|
791
821
|
b.use :label_input
|
|
792
|
-
b.wrapper :
|
|
793
|
-
component.optional :hint, :
|
|
794
|
-
component.use :error, :
|
|
822
|
+
b.wrapper tag: :div, class: 'separator' do |component|
|
|
823
|
+
component.optional :hint, wrap_with: { tag: :span, class: :hint }
|
|
824
|
+
component.use :error, wrap_with: { tag: :span, class: :error }
|
|
795
825
|
end
|
|
796
826
|
end
|
|
797
827
|
```
|
|
798
828
|
|
|
799
|
-
By setting it as `optional`, a hint will only be generated when
|
|
800
|
-
The same for
|
|
829
|
+
By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
|
|
830
|
+
The same for placeholder.
|
|
801
831
|
|
|
802
832
|
## HTML 5 Notice
|
|
803
833
|
|
|
@@ -831,7 +861,7 @@ help you to use some generic javascript validation.
|
|
|
831
861
|
You can also add `novalidate` to a specific form by setting the option on the form itself:
|
|
832
862
|
|
|
833
863
|
```erb
|
|
834
|
-
<%= simple_form_for(resource, :
|
|
864
|
+
<%= simple_form_for(resource, html: {novalidate: true}) do |form| %>
|
|
835
865
|
```
|
|
836
866
|
|
|
837
867
|
Please notice that any of the configurations above will disable the `placeholder` component,
|
|
@@ -876,3 +906,5 @@ https://github.com/plataformatec/simple_form/issues
|
|
|
876
906
|
## License
|
|
877
907
|
|
|
878
908
|
MIT License. Copyright 2009-2013 Plataformatec. http://plataformatec.com.br
|
|
909
|
+
|
|
910
|
+
You are not granted rights or licenses to the trademarks of the Plataformatec, including without limitation the Simple Form name or logo.
|
|
@@ -3,9 +3,9 @@ module SimpleForm
|
|
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
|
4
4
|
desc "Copy SimpleForm default files"
|
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
-
class_option :template_engine, :
|
|
7
|
-
class_option :bootstrap, :
|
|
8
|
-
class_option :foundation, :
|
|
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.'
|
|
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?
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
classes, '.form-horizontal', '.form-inline', '.form-search' or
|
|
8
8
|
'.form-vertical', as the following:
|
|
9
9
|
|
|
10
|
-
= simple_form_for(@user, :
|
|
10
|
+
= simple_form_for(@user, html: {class: 'form-horizontal' }) do |form|
|
|
11
11
|
|
|
12
12
|
===============================================================================
|
|
@@ -5,8 +5,8 @@ SimpleForm.setup do |config|
|
|
|
5
5
|
# wrapper, change the order or even add your own to the
|
|
6
6
|
# stack. The options given below are used to wrap the
|
|
7
7
|
# whole input.
|
|
8
|
-
config.wrappers :default, :
|
|
9
|
-
:
|
|
8
|
+
config.wrappers :default, class: :input,
|
|
9
|
+
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
|
10
10
|
## Extensions enabled by default
|
|
11
11
|
# Any of these extensions can be disabled for a
|
|
12
12
|
# given input by passing: `f.input EXTENSION_NAME => false`.
|
|
@@ -18,7 +18,7 @@ SimpleForm.setup do |config|
|
|
|
18
18
|
b.use :html5
|
|
19
19
|
|
|
20
20
|
# Calculates placeholders automatically from I18n
|
|
21
|
-
# You can also pass a string as f.input :
|
|
21
|
+
# You can also pass a string as f.input placeholder: "Placeholder"
|
|
22
22
|
b.use :placeholder
|
|
23
23
|
|
|
24
24
|
## Optional extensions
|
|
@@ -41,8 +41,8 @@ SimpleForm.setup do |config|
|
|
|
41
41
|
|
|
42
42
|
## Inputs
|
|
43
43
|
b.use :label_input
|
|
44
|
-
b.use :hint, :
|
|
45
|
-
b.use :error, :
|
|
44
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
|
45
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
# The default wrapper to be used by the FormBuilder.
|
|
@@ -50,8 +50,8 @@ SimpleForm.setup do |config|
|
|
|
50
50
|
|
|
51
51
|
# Define the way to render check boxes / radio buttons with labels.
|
|
52
52
|
# Defaults to :nested for bootstrap config.
|
|
53
|
-
# :
|
|
54
|
-
# :
|
|
53
|
+
# inline: input + label
|
|
54
|
+
# nested: label > input
|
|
55
55
|
config.boolean_style = :nested
|
|
56
56
|
|
|
57
57
|
# Default class for buttons
|
|
@@ -106,8 +106,11 @@ SimpleForm.setup do |config|
|
|
|
106
106
|
# Whether attributes are required by default (or not). Default is true.
|
|
107
107
|
# config.required_by_default = true
|
|
108
108
|
|
|
109
|
-
# Tell browsers whether to use
|
|
110
|
-
#
|
|
109
|
+
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
|
|
110
|
+
# These validations are enabled in SimpleForm's internal config but disabled by default
|
|
111
|
+
# in this configuration, which is recommended due to some quirks from different browsers.
|
|
112
|
+
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
|
|
113
|
+
# change this configuration to true.
|
|
111
114
|
config.browser_validations = false
|
|
112
115
|
|
|
113
116
|
# Collection of methods to detect if a file type was given.
|
|
@@ -120,7 +123,7 @@ SimpleForm.setup do |config|
|
|
|
120
123
|
|
|
121
124
|
# Custom wrappers for input types. This should be a hash containing an input
|
|
122
125
|
# type as key and the wrapper that will be used for all inputs with specified type.
|
|
123
|
-
# config.wrapper_mappings = { :
|
|
126
|
+
# config.wrapper_mappings = { string: :prepend }
|
|
124
127
|
|
|
125
128
|
# Default priority for time_zone inputs.
|
|
126
129
|
# config.time_zone_priority = nil
|
|
@@ -128,9 +131,6 @@ SimpleForm.setup do |config|
|
|
|
128
131
|
# Default priority for country inputs.
|
|
129
132
|
# config.country_priority = nil
|
|
130
133
|
|
|
131
|
-
# Default size for text inputs.
|
|
132
|
-
# config.default_input_size = 50
|
|
133
|
-
|
|
134
134
|
# When false, do not use translations for labels.
|
|
135
135
|
# config.translate_labels = true
|
|
136
136
|
|