simple_form 1.5.2 → 2.0.0

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 (108) hide show
  1. data/CHANGELOG.md +234 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +816 -0
  4. data/lib/generators/simple_form/install_generator.rb +15 -1
  5. data/lib/generators/simple_form/templates/README +12 -0
  6. data/lib/generators/simple_form/templates/_form.html.erb +2 -2
  7. data/lib/generators/simple_form/templates/_form.html.haml +2 -2
  8. data/lib/generators/simple_form/templates/_form.html.slim +4 -4
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +176 -0
  10. data/lib/simple_form/action_view_extensions/builder.rb +206 -59
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +30 -23
  12. data/lib/simple_form/components/errors.rb +6 -24
  13. data/lib/simple_form/components/hints.rb +7 -21
  14. data/lib/simple_form/components/html5.rb +26 -0
  15. data/lib/simple_form/components/labels.rb +22 -14
  16. data/lib/simple_form/components/maxlength.rb +41 -0
  17. data/lib/simple_form/components/min_max.rb +49 -0
  18. data/lib/simple_form/components/pattern.rb +34 -0
  19. data/lib/simple_form/components/placeholders.rb +5 -17
  20. data/lib/simple_form/components/readonly.rb +22 -0
  21. data/lib/simple_form/components.rb +11 -1
  22. data/lib/simple_form/core_ext/hash.rb +16 -0
  23. data/lib/simple_form/error_notification.rb +9 -3
  24. data/lib/simple_form/form_builder.rb +105 -28
  25. data/lib/simple_form/helpers/autofocus.rb +11 -0
  26. data/lib/simple_form/helpers/disabled.rb +15 -0
  27. data/lib/simple_form/helpers/readonly.rb +15 -0
  28. data/lib/simple_form/helpers/required.rb +10 -11
  29. data/lib/simple_form/helpers/validators.rb +4 -4
  30. data/lib/simple_form/helpers.rb +7 -4
  31. data/lib/simple_form/inputs/base.rb +53 -81
  32. data/lib/simple_form/inputs/boolean_input.rb +46 -4
  33. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  34. data/lib/simple_form/inputs/collection_input.rb +27 -13
  35. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +67 -0
  36. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  37. data/lib/simple_form/inputs/date_time_input.rb +10 -6
  38. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  39. data/lib/simple_form/inputs/hidden_input.rb +3 -6
  40. data/lib/simple_form/inputs/numeric_input.rb +3 -51
  41. data/lib/simple_form/inputs/password_input.rb +1 -2
  42. data/lib/simple_form/inputs/priority_input.rb +2 -2
  43. data/lib/simple_form/inputs/range_input.rb +1 -3
  44. data/lib/simple_form/inputs/string_input.rb +6 -8
  45. data/lib/simple_form/inputs/text_input.rb +1 -2
  46. data/lib/simple_form/inputs.rb +17 -13
  47. data/lib/simple_form/version.rb +1 -1
  48. data/lib/simple_form/wrappers/builder.rb +103 -0
  49. data/lib/simple_form/wrappers/many.rb +69 -0
  50. data/lib/simple_form/wrappers/root.rb +34 -0
  51. data/lib/simple_form/wrappers/single.rb +18 -0
  52. data/lib/simple_form/wrappers.rb +8 -0
  53. data/lib/simple_form.rb +118 -48
  54. data/test/action_view_extensions/builder_test.rb +285 -102
  55. data/test/action_view_extensions/form_helper_test.rb +32 -10
  56. data/test/components/label_test.rb +44 -5
  57. data/test/form_builder/association_test.rb +177 -0
  58. data/test/form_builder/button_test.rb +47 -0
  59. data/test/{error_notification_test.rb → form_builder/error_notification_test.rb} +18 -1
  60. data/test/form_builder/error_test.rb +121 -0
  61. data/test/form_builder/general_test.rb +356 -0
  62. data/test/form_builder/hint_test.rb +123 -0
  63. data/test/form_builder/input_field_test.rb +63 -0
  64. data/test/form_builder/label_test.rb +65 -0
  65. data/test/form_builder/wrapper_test.rb +149 -0
  66. data/test/generators/simple_form_generator_test.rb +32 -0
  67. data/test/inputs/boolean_input_test.rb +101 -0
  68. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  69. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  70. data/test/inputs/collection_select_input_test.rb +241 -0
  71. data/test/inputs/datetime_input_test.rb +99 -0
  72. data/test/inputs/disabled_test.rb +38 -0
  73. data/test/inputs/discovery_test.rb +61 -0
  74. data/test/inputs/file_input_test.rb +16 -0
  75. data/test/inputs/general_test.rb +69 -0
  76. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  77. data/test/inputs/hidden_input_test.rb +30 -0
  78. data/test/inputs/numeric_input_test.rb +167 -0
  79. data/test/inputs/priority_input_test.rb +43 -0
  80. data/test/inputs/readonly_test.rb +61 -0
  81. data/test/inputs/required_test.rb +113 -0
  82. data/test/inputs/string_input_test.rb +140 -0
  83. data/test/inputs/text_input_test.rb +24 -0
  84. data/test/support/misc_helpers.rb +53 -12
  85. data/test/support/mock_controller.rb +2 -2
  86. data/test/support/models.rb +20 -5
  87. data/test/test_helper.rb +11 -12
  88. metadata +124 -96
  89. data/.gitignore +0 -3
  90. data/.gitmodules +0 -3
  91. data/.travis.yml +0 -15
  92. data/CHANGELOG.rdoc +0 -159
  93. data/Gemfile +0 -9
  94. data/README.rdoc +0 -466
  95. data/Rakefile +0 -27
  96. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +0 -93
  97. data/lib/simple_form/components/wrapper.rb +0 -38
  98. data/lib/simple_form/helpers/has_errors.rb +0 -15
  99. data/lib/simple_form/helpers/maxlength.rb +0 -24
  100. data/lib/simple_form/helpers/pattern.rb +0 -28
  101. data/simple_form.gemspec +0 -25
  102. data/test/components/error_test.rb +0 -56
  103. data/test/components/hint_test.rb +0 -74
  104. data/test/components/wrapper_test.rb +0 -63
  105. data/test/custom_components.rb +0 -7
  106. data/test/form_builder_test.rb +0 -930
  107. data/test/inputs_test.rb +0 -995
  108. /data/test/{discovery_inputs.rb → support/discovery_inputs.rb} +0 -0
data/README.rdoc DELETED
@@ -1,466 +0,0 @@
1
- == SimpleForm
2
-
3
- Forms made easy (for Rails)!
4
-
5
- SimpleForm aims to be as flexible as possible while helping you with powerful components to create your forms. The basic goal of simple form is to not touch your way of defining the layout, letting you find the better design for your eyes. Good part of the DSL was inherited from Formtastic, which we are thankful for and should make you feel right at home.
6
-
7
- == Information
8
-
9
- === Google Group
10
-
11
- If you have any questions, comments, or concerns please use the Google Group instead of the GitHub Issues tracker:
12
-
13
- http://groups.google.com/group/plataformatec-simpleform
14
-
15
- === RDocs
16
-
17
- You can view the SimpleForm documentation in RDoc format here:
18
-
19
- http://rubydoc.info/github/plataformatec/simple_form/master/frames
20
-
21
- If you need to use SimpleForm with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
22
-
23
- === Bug reports
24
-
25
- If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug. We also encourage you to help even more by forking and sending us a pull request.
26
-
27
- http://github.com/plataformatec/simple_form/issues
28
-
29
- == Installation
30
-
31
- Install the gem:
32
-
33
- gem install simple_form
34
-
35
- Add it to your Gemfile:
36
-
37
- gem "simple_form"
38
-
39
- Run the generator:
40
-
41
- rails generate simple_form:install
42
-
43
- Also, if you want to use the country select, you will need the country_select plugin, install with following command:
44
-
45
- rails plugin install git://github.com/rails/country_select.git
46
-
47
- And you are ready to go. Since this branch aims Rails 3 support,
48
- if you want to use it with Rails 2.3 you should check this branch:
49
-
50
- http://github.com/plataformatec/simple_form/tree/v1.0
51
-
52
- == Usage
53
-
54
- SimpleForm was designed to be customized as you need to. Basically it's a stack of components that are invoked to create a complete html input for you, which by default contains label, hints, errors and the input itself. It does not aim to create a lot of different logic from the default Rails form helpers, as they do a great work by themselves. Instead, SimpleForm acts as a DSL and just maps your input type (retrieved from the column definition in the database) to an specific helper method.
55
-
56
- To start using SimpleForm you just have to use the helper it provides:
57
-
58
- <%= simple_form_for @user do |f| %>
59
- <%= f.input :username %>
60
- <%= f.input :password %>
61
- <%= f.button :submit %>
62
- <% end %>
63
-
64
- This will generate an entire form with labels for user name and password as well, and render errors by default when you render the form with invalid data (after submitting for example).
65
-
66
- You can overwrite the default label by passing it to the input method, add a hint or even a placeholder:
67
-
68
- <%= simple_form_for @user do |f| %>
69
- <%= f.input :username, :label => 'Your username please' %>
70
- <%= f.input :password, :hint => 'No special characters.' %>
71
- <%= f.input :email, :placeholder => 'user@domain.com' %>
72
- <%= f.button :submit %>
73
- <% end %>
74
-
75
- You can also disable labels, hints or error or configure the html of any of them:
76
-
77
- <%= simple_form_for @user do |f| %>
78
- <%= f.input :username, :label_html => { :class => 'my_class' } %>
79
- <%= f.input :password, :hint => false, :error_html => { :id => "password_error"} %>
80
- <%= f.input :password_confirmation, :label => false %>
81
- <%= f.button :submit %>
82
- <% end %>
83
-
84
- It is also possible to pass any html attribute straight to the input, by using the :input_html option, for instance:
85
-
86
- <%= simple_form_for @user do |f| %>
87
- <%= f.input :username, :input_html => { :class => 'special' } %>
88
- <%= f.input :password, :input_html => { :maxlength => 20 } %>
89
- <%= f.input :remember_me, :input_html => { :value => '1' } %>
90
- <%= f.button :submit %>
91
- <% end %>
92
-
93
- By default all inputs are required, which means an * is prepended to the label, but you can disable it in any input you want:
94
-
95
- <%= simple_form_for @user do |f| %>
96
- <%= f.input :name, :required => false %>
97
- <%= f.input :username %>
98
- <%= f.input :password %>
99
- <%= f.button :submit %>
100
- <% end %>
101
-
102
- SimpleForm also lets you overwrite the default input type it creates:
103
-
104
- <%= simple_form_for @user do |f| %>
105
- <%= f.input :username %>
106
- <%= f.input :password %>
107
- <%= f.input :description, :as => :text %>
108
- <%= f.input :accepts, :as => :radio %>
109
- <%= f.button :submit %>
110
- <% end %>
111
-
112
- So instead of a checkbox for the :accepts attribute, you'll have a pair of radio buttons with yes/no labels and a text area instead of a text field for the description. You can also render boolean attributes using :as => :select to show a dropdown.
113
-
114
- It is also possible to give the :disabled option to SimpleForm, and it'll automatically mark the wrapper as disabled with a css class, so you can style labels, hints and other components inside the wrapper as well:
115
-
116
- <%= simple_form_for @user do |f| %>
117
- <%= f.input :username, :disabled => true, :hint => "You cannot change your username." %>
118
- <%= f.button :submit %>
119
- <% end %>
120
-
121
- SimpleForm accepts same options as their corresponding input type helper in Rails:
122
-
123
- <%= simple_form_for @user do |f| %>
124
- <%= f.input :date_of_birth, :as => :date, :start_year => Date.today.year - 90,
125
- :end_year => Date.today.year - 12, :discard_day => true,
126
- :order => [:month, :year] %>
127
- <%= f.button :submit %>
128
- <% end %>
129
-
130
- SimpleForm also allows you to use label, hint, input_field, error and full_error helpers it provides (please take a look at the rdocs for each method for more info):
131
-
132
- <%= simple_form_for @user do |f| %>
133
- <%= f.label :username %>
134
- <%= f.input_field :username %>
135
- <%= f.hint 'No special characters, please!' %>
136
- <%= f.error :username, :id => 'user_name_error' %>
137
- <%= f.full_error :token %>
138
- <%= f.submit 'Save' %>
139
- <% end %>
140
-
141
- Any extra option passed to these methods will be rendered as html option.
142
-
143
- === Collections
144
-
145
- And what if you want to create a select containing the age from 18 to 60 in your form? You can do it overriding the :collection option:
146
-
147
- <%= simple_form_for @user do |f| %>
148
- <%= f.input :user %>
149
- <%= f.input :age, :collection => 18..60 %>
150
- <%= f.button :submit %>
151
- <% end %>
152
-
153
- Collections can be arrays or ranges, and when a :collection is given the :select input will be rendered by default, so we don't need to pass the :as => :select option. Other types of collection are :radio and :check_boxes. Those are added by SimpleForm to Rails set of form helpers (read Extra Helpers session below for more information).
154
-
155
- Collection inputs accepts two other options beside collections:
156
-
157
- * label_method => the label method to be applied to the collection to retrieve the label
158
-
159
- * value_method => the value method to be applied to the collection to retrieve the value
160
-
161
- Those methods are useful to manipulate the given collection. Both of these options also accept lambda/procs in case you want to calculate the value or label in a special way eg. custom translation. All other options given are sent straight to the underlying helper. For example, you can give prompt as:
162
-
163
- f.input :age, :collection => 18..60, :prompt => "Select your age"
164
-
165
- === Priority
166
-
167
- SimpleForm also supports :time_zone and :country. When using such helpers, you can give :priority as option to select which time zones and/or countries should be given higher priority:
168
-
169
- f.input :residence_country, :priority => [ "Brazil" ]
170
- f.input :time_zone, :priority => /US/
171
-
172
- Those values can also be configured with a default value to be used site use through the SimpleForm.country_priority and SimpleForm.time_zone_priority helpers.
173
-
174
- === Wrapper
175
-
176
- SimpleForm allows you to add a wrapper which contains the label, error, hint and input.
177
- The first step is to configure a wrapper tag:
178
-
179
- SimpleForm.wrapper_tag = :p
180
-
181
- And now, you don't need to wrap your f.input calls anymore:
182
-
183
- <%= simple_form_for @user do |f| %>
184
- <%= f.input :username %>
185
- <%= f.input :password %>
186
- <%= f.button :submit %>
187
- <% end %>
188
-
189
- == Associations
190
-
191
- To deal with associations, SimpleForm can generate select inputs, a series of radios or check boxes. Lets see how it works: imagine you have a user model that belongs to a company and has_and_belongs_to_many roles. The structure would be something like:
192
-
193
- class User < ActiveRecord::Base
194
- belongs_to :company
195
- has_and_belongs_to_many :roles
196
- end
197
-
198
- class Company < ActiveRecord::Base
199
- has_many :users
200
- end
201
-
202
- class Role < ActiveRecord::Base
203
- has_and_belongs_to_many :users
204
- end
205
-
206
- Now we have the user form:
207
-
208
- <%= simple_form_for @user do |f| %>
209
- <%= f.input :name %>
210
- <%= f.association :company %>
211
- <%= f.association :roles %>
212
- <%= f.button :submit %>
213
- <% end %>
214
-
215
- Simple enough right? This is going to render a :select input for choosing the :company, and another :select input with :multiple option for the :roles. You can of course change it, to use radios and check boxes as well:
216
-
217
- f.association :company, :as => :radio
218
- f.association :roles, :as => :check_boxes
219
-
220
- The association helper just invokes input under the hood, so all options available to :select, :radio and :check_boxes are also available to association. Additionally, you can specify the collection by hand, all together with the prompt:
221
-
222
- f.association :company, :collection => Company.active.all(:order => 'name'), :prompt => "Choose a Company"
223
-
224
- == Buttons
225
-
226
- All web forms need buttons, right? SimpleForm wraps them in the DSL, acting like a proxy:
227
-
228
- <%= simple_form_for @user do |f| %>
229
- <%= f.input :name %>
230
- <%= f.button :submit %>
231
- <% end %>
232
-
233
- The above will simply call submit. You choose to use it or not, it's just a question of taste.
234
-
235
- == Wrapping Rails Form Helpers
236
-
237
- Say you wanted to use a rails form helper but still wrap it in SimpleForm goodness? You can, by calling input with a block like so:
238
-
239
- <%= f.input :role do %>
240
- <%= f.select :role, Role.all.map { |r| [r.name, r.id, { :class => r.company.id }] }, :include_blank => true %>
241
- <% end %>
242
-
243
- In the above example, we're taking advantage of Rails 3's select method that allows us to pass in a hash of additional attributes for each option.
244
-
245
- == Extra helpers
246
-
247
- SimpleForm also comes with some extra helpers you can use inside rails default forms without relying on simple_form_for helper. They are listed below.
248
-
249
- === Simple Fields For
250
-
251
- Wrapper to use simple form inside a default rails form
252
-
253
- form_for @user do |f|
254
- f.simple_fields_for :posts do |posts_form|
255
- # Here you have all simple_form methods available
256
- posts_form.input :title
257
- end
258
- end
259
-
260
- === Collection Radio
261
-
262
- Creates a collection of radio inputs with labels associated (same API as collection_select):
263
-
264
- form_for @user do |f|
265
- f.collection_radio :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
266
- end
267
-
268
- <input id="user_options_true" name="user[options]" type="radio" value="true" />
269
- <label class="collection_radio" for="user_options_true">Yes</label>
270
- <input id="user_options_false" name="user[options]" type="radio" value="false" />
271
- <label class="collection_radio" for="user_options_false">No</label>
272
-
273
- === Collection Check Box
274
-
275
- Creates a collection of check boxes with labels associated (same API as collection_select):
276
-
277
- form_for @user do |f|
278
- f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
279
- end
280
-
281
- <input name="user[options][]" type="hidden" value="" />
282
- <input id="user_options_true" name="user[options][]" type="checkbox" value="true" />
283
- <label class="collection_check_box" for="user_options_true">Yes</label>
284
- <input name="user[options][]" type="hidden" value="" />
285
- <input id="user_options_false" name="user[options][]" type="checkbox" value="false" />
286
- <label class="collection_check_box" for="user_options_false">No</label>
287
-
288
- To use this with associations in your model, you can do the following:
289
-
290
- form_for @user do |f|
291
- f.collection_check_boxes :role_ids, Role.all, :id, :name # using :roles here is not going to work.
292
- end
293
-
294
-
295
- == Mappings/Inputs available
296
-
297
- SimpleForm comes with a lot of default mappings:
298
-
299
- Mapping Input Column Type
300
-
301
- boolean check box boolean
302
- string text field string
303
- email email field string with name matching "email"
304
- url url field string with name matching "url"
305
- tel tel field string with name matching "phone"
306
- password password field string with name matching "password"
307
- search search -
308
- text text area text
309
- file file field string, responding to file methods
310
- hidden hidden field -
311
- integer number field integer
312
- float number field float
313
- decimal number field decimal
314
- range range field -
315
- datetime datetime select datetime/timestamp
316
- date date select date
317
- time time select time
318
- select collection select belongs_to/has_many/has_and_belongs_to_many associations
319
- radio collection radio belongs_to
320
- check_boxes collection check box has_many/has_and_belongs_to_many associations
321
- country country select string with name matching "country"
322
- time_zone time zone select string with name matching "time_zone"
323
-
324
- == Custom inputs
325
-
326
- It is very easy to add custom inputs to SimpleForm. For instance, if you want to add a custom input that extends the string one, you just need to add this file:
327
-
328
- # app/inputs/currency_input.rb
329
- class CurrencyInput < SimpleForm::Inputs::Base
330
- def input
331
- "$ #{@builder.text_field(attribute_name, input_html_options)}".html_safe
332
- end
333
- end
334
-
335
- And use it in your views:
336
-
337
- f.input :money, :as => :currency
338
-
339
- You can also redefine existing SimpleForm inputs by creating a new class with the same name. For instance, if you want to wrap date/time/datetime in a div, you can do:
340
-
341
- # app/inputs/date_time_input.rb
342
- class DateTimeInput < SimpleForm::Inputs::DateTimeInput
343
- def input
344
- "<div>#{super}</div>".html_safe
345
- end
346
- end
347
-
348
- == Custom form builder
349
-
350
- You can create a custom form builder that uses SimpleForm.
351
-
352
- Create a helper method that calls simple_form_for with a custom builder:
353
-
354
- def custom_form_for(object, *args, &block)
355
- options = args.extract_options!
356
- simple_form_for(object, *(args << options.merge(:builder => CustomFormBuilder)), &block)
357
- end
358
-
359
- Create a form builder class that inherits from SimpleForm::FormBuilder.
360
-
361
- class CustomFormBuilder < SimpleForm::FormBuilder
362
- def input(attribute_name, options = {}, &block)
363
- options[:input_html].merge! :class => 'custom'
364
- super
365
- end
366
- end
367
-
368
- == I18n
369
-
370
- SimpleForm uses all power of I18n API to lookup labels, hints and placeholders. To customize your forms you can create a locale file like this:
371
-
372
- en:
373
- simple_form:
374
- labels:
375
- user:
376
- username: 'User name'
377
- password: 'Password'
378
- hints:
379
- user:
380
- username: 'User name to sign in.'
381
- password: 'No special characters, please.'
382
- placeholders:
383
- user:
384
- username: 'Your username'
385
- password: '****'
386
-
387
- And your forms will use this information to render the components for you.
388
-
389
- SimpleForm also lets you be more specific, separating lookups through actions for labels, hints and placeholders. Let's say you want a different label for new and edit actions, the locale file would be something like:
390
-
391
- en:
392
- simple_form:
393
- labels:
394
- user:
395
- username: 'User name'
396
- password: 'Password'
397
- edit:
398
- username: 'Change user name'
399
- password: 'Change password'
400
-
401
- This way SimpleForm will figure out the right translation for you, based on the action being rendered. And to be a little bit DRYer with your locale file, you can skip the model information inside it:
402
-
403
- en:
404
- simple_form:
405
- labels:
406
- username: 'User name'
407
- password: 'Password'
408
- hints:
409
- username: 'User name to sign in.'
410
- password: 'No special characters, please.'
411
- placeholders:
412
- username: 'Your username'
413
- password: '****'
414
-
415
- SimpleForm will always look for a default attribute translation if no specific is found inside the model key. In addition, SimpleForm will fallback to default human_attribute_name from Rails when no other translation is found for labels.
416
-
417
- Finally, you can also overwrite any label, hint or placeholder inside your view, just by passing the option manually. This way the I18n lookup will be skipped.
418
-
419
- It's also possible to translate buttons, using Rails' built-in I18n support:
420
-
421
- en:
422
- helpers:
423
- submit:
424
- user:
425
- create: "Add %{model}"
426
- update: "Save Changes"
427
-
428
- There are other options that can be configured through I18n API, such as required text and boolean. Be sure to check our locale file or the one copied to your application after you run "rails generate simple_form:install".
429
-
430
- == HTML 5 Notice
431
-
432
- By default, SimpleForm will generate input field types and attributes that are supported in HTML5, but are considered invalid HTML for older document types such as HTML4 or XHTML1.0. The HTML5 extensions include the new field types such as email, number, search, url, tel, and the new attributes such as required, autofocus, maxlength, min, max, step.
433
-
434
- Most browsers will not care, but some of the newer ones - in particular Chrome 10+ - use the required attribute to force a value into an input and will prevent form submission without it. Depending on the design of the application this may or may not be desired. In many cases it can break existing UI's.
435
-
436
- It is possible to disable all HTML 5 extensions in SimpleForm with the following configuration:
437
-
438
- SimpleForm.html5 = false # default is true
439
-
440
- If you want to have all other HTML 5 features, such as the new field types, you can disable only the browser validation:
441
-
442
- SimpleForm.browser_validations = false # default is true
443
-
444
- This option adds a new `novalidate` property to the form, instructing it to skip all HTML 5 validation. The inputs will still be generated with the required and other attributes, that might help you to use some generic javascript validation.
445
-
446
- You can also add `novalidate` to a specific form by setting the option on the form itself:
447
-
448
- <%= simple_form_for(resource, :html => {:novalidate => true}) do |form| %>
449
-
450
- Please notice that any of the configurations above will disable the `placeholder` component, which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute fine, and if they aren't, any plugin you use would take of using the placeholder attribute to do it. However, you can disable it if you want, by removing the placeholder component from the components list in SimpleForm configuration file.
451
-
452
- == Configuration
453
-
454
- SimpleForm has several configuration values. You can read and change them in the initializer created by SimpleForm, so if you haven't executed the command below yet, please do:
455
-
456
- rails generate simple_form:install
457
-
458
- == Maintainers
459
-
460
- * Carlos Antonio da Silva (https://github.com/carlosantoniodasilva)
461
- * Rafael Mendonça França (https://github.com/rafaelfranca)
462
-
463
- == License
464
-
465
- MIT License. Copyright 2011 Plataforma Tecnologia. http://blog.plataformatec.com.br
466
-
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'bundler'
4
- Bundler::GemHelper.install_tasks
5
-
6
- require 'rake/testtask'
7
- require 'rdoc/task'
8
-
9
- desc 'Default: run unit tests.'
10
- task :default => :test
11
-
12
- desc 'Test the simple_form plugin.'
13
- Rake::TestTask.new(:test) do |t|
14
- t.libs << 'lib'
15
- t.libs << 'test'
16
- t.pattern = 'test/**/*_test.rb'
17
- t.verbose = true
18
- end
19
-
20
- desc 'Generate documentation for the simple_form plugin.'
21
- Rake::RDocTask.new(:rdoc) do |rdoc|
22
- rdoc.rdoc_dir = 'rdoc'
23
- rdoc.title = 'SimpleForm'
24
- rdoc.options << '--line-numbers' << '--inline-source'
25
- rdoc.rdoc_files.include('README.rdoc')
26
- rdoc.rdoc_files.include('lib/**/*.rb')
27
- end
@@ -1,93 +0,0 @@
1
- # Use this setup block to configure all options available in SimpleForm.
2
- SimpleForm.setup do |config|
3
- # Components used by the form builder to generate a complete input. You can remove
4
- # any of them, change the order, or even add your own components to the stack.
5
- # config.components = [ :placeholder, :label_input, :hint, :error ]
6
-
7
- # Default tag used on hints.
8
- # config.hint_tag = :span
9
-
10
- # CSS class to add to all hint tags.
11
- # config.hint_class = :hint
12
-
13
- # CSS class used on errors.
14
- # config.error_class = :error
15
-
16
- # Default tag used on errors.
17
- # config.error_tag = :span
18
-
19
- # Method used to tidy up errors.
20
- # config.error_method = :first
21
-
22
- # Default tag used for error notification helper.
23
- # config.error_notification_tag = :p
24
-
25
- # CSS class to add for error notification helper.
26
- # config.error_notification_class = :error_notification
27
-
28
- # ID to add for error notification helper.
29
- # config.error_notification_id = nil
30
-
31
- # You can wrap all inputs in a pre-defined tag.
32
- # config.wrapper_tag = :div
33
-
34
- # CSS class to add to all wrapper tags.
35
- # config.wrapper_class = :input
36
-
37
- # CSS class to add to the wrapper if the field has errors.
38
- # config.wrapper_error_class = :field_with_errors
39
-
40
- # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
41
- # config.collection_wrapper_tag = nil
42
-
43
- # You can wrap each item in a collection of radio/check boxes with a tag, defaulting to span.
44
- # config.item_wrapper_tag = :span
45
-
46
- # Series of attempts to detect a default label method for collection.
47
- # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
48
-
49
- # Series of attempts to detect a default value method for collection.
50
- # config.collection_value_methods = [ :id, :to_s ]
51
-
52
- # How the label text should be generated altogether with the required text.
53
- # config.label_text = lambda { |label, required| "#{required} #{label}" }
54
-
55
- # You can define the class to use on all labels. Default is nil.
56
- # config.label_class = nil
57
-
58
- # You can define the class to use on all forms. Default is simple_form.
59
- # config.form_class = :simple_form
60
-
61
- # Whether attributes are required by default (or not). Default is true.
62
- # config.required_by_default = true
63
-
64
- # Tell browsers whether to use default HTML5 validations (novalidate option).
65
- # Default is enabled.
66
- # config.browser_validations = true
67
-
68
- # Determines whether HTML5 types (:email, :url, :search, :tel) and attributes
69
- # (e.g. required) are used or not. True by default.
70
- # Having this on in non-HTML5 compliant sites can cause odd behavior in
71
- # HTML5-aware browsers such as Chrome.
72
- # config.html5 = true
73
-
74
- # Custom mappings for input types. This should be a hash containing a regexp
75
- # to match as key, and the input type that will be used when the field name
76
- # matches the regexp as value.
77
- # config.input_mappings = { /count/ => :integer }
78
-
79
- # Collection of methods to detect if a file type was given.
80
- # config.file_methods = [ :mounted_as, :file?, :public_filename ]
81
-
82
- # Default priority for time_zone inputs.
83
- # config.time_zone_priority = nil
84
-
85
- # Default priority for country inputs.
86
- # config.country_priority = nil
87
-
88
- # Default size for text inputs.
89
- # config.default_input_size = 50
90
-
91
- # When false, do not use translations for labels, hints or placeholders.
92
- # config.translate = true
93
- end
@@ -1,38 +0,0 @@
1
- module SimpleForm
2
- module Components
3
- module Wrapper
4
- def wrap(content)
5
- if wrapper_tag && options[:wrapper] != false
6
- template.content_tag(wrapper_tag, content, wrapper_html_options)
7
- else
8
- content
9
- end
10
- end
11
-
12
- def wrapper_tag
13
- options[:wrapper_tag] || SimpleForm.wrapper_tag
14
- end
15
-
16
- def wrapper_class
17
- options[:wrapper_class] || SimpleForm.wrapper_class
18
- end
19
-
20
- def wrapper_error_class
21
- options[:wrapper_error_class] || SimpleForm.wrapper_error_class
22
- end
23
-
24
- def wrapper_html_options
25
- css_classes = input_html_classes.unshift(wrapper_class)
26
- css_classes << wrapper_error_class if has_errors?
27
- css_classes << disabled_class if disabled?
28
- html_options_for(:wrapper, css_classes)
29
- end
30
-
31
- private
32
-
33
- def disabled_class
34
- 'disabled'
35
- end
36
- end
37
- end
38
- end
@@ -1,15 +0,0 @@
1
- module SimpleForm
2
- module Helpers
3
- module HasErrors
4
- private
5
-
6
- def errors
7
- object.errors
8
- end
9
-
10
- def has_errors?
11
- object && object.respond_to?(:errors) && errors.present?
12
- end
13
- end
14
- end
15
- end
@@ -1,24 +0,0 @@
1
- module SimpleForm
2
- module Helpers
3
- # Helper methods for maxlength.
4
- module Maxlength #:nodoc:
5
-
6
- private
7
-
8
- def add_maxlength!
9
- input_html_options[:maxlength] ||= maximum_length_from_validation || limit if SimpleForm.html5
10
- end
11
-
12
- def maximum_length_from_validation
13
- return unless has_validators?
14
-
15
- length_validator = find_length_validator or return
16
- length_validator.options[:maximum]
17
- end
18
-
19
- def find_length_validator
20
- find_validator(ActiveModel::Validations::LengthValidator)
21
- end
22
- end
23
- end
24
- end