simple_form 3.1.0.rc2 → 3.2.1

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -1
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +76 -24
  5. data/lib/generators/simple_form/install_generator.rb +2 -2
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +4 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +22 -2
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
  9. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  10. data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
  11. data/lib/simple_form/components/errors.rb +3 -5
  12. data/lib/simple_form/components/html5.rb +4 -4
  13. data/lib/simple_form/components/labels.rb +1 -1
  14. data/lib/simple_form/form_builder.rb +9 -7
  15. data/lib/simple_form/inputs/base.rb +1 -5
  16. data/lib/simple_form/inputs/boolean_input.rb +1 -1
  17. data/lib/simple_form/inputs/collection_input.rb +2 -4
  18. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
  19. data/lib/simple_form/inputs/date_time_input.rb +12 -8
  20. data/lib/simple_form/tags.rb +2 -4
  21. data/lib/simple_form/version.rb +1 -1
  22. data/lib/simple_form.rb +13 -2
  23. data/test/action_view_extensions/builder_test.rb +31 -31
  24. data/test/action_view_extensions/form_helper_test.rb +20 -1
  25. data/test/components/label_test.rb +1 -1
  26. data/test/form_builder/association_test.rb +37 -37
  27. data/test/form_builder/button_test.rb +5 -5
  28. data/test/form_builder/error_test.rb +75 -16
  29. data/test/form_builder/general_test.rb +42 -11
  30. data/test/form_builder/hint_test.rb +3 -3
  31. data/test/form_builder/input_field_test.rb +59 -53
  32. data/test/form_builder/label_test.rb +13 -3
  33. data/test/form_builder/wrapper_test.rb +29 -14
  34. data/test/generators/simple_form_generator_test.rb +2 -2
  35. data/test/inputs/boolean_input_test.rb +9 -1
  36. data/test/inputs/collection_check_boxes_input_test.rb +22 -0
  37. data/test/inputs/collection_radio_buttons_input_test.rb +25 -3
  38. data/test/inputs/collection_select_input_test.rb +17 -17
  39. data/test/inputs/datetime_input_test.rb +6 -1
  40. data/test/inputs/grouped_collection_select_input_test.rb +8 -8
  41. data/test/inputs/numeric_input_test.rb +19 -19
  42. data/test/inputs/priority_input_test.rb +6 -6
  43. data/test/inputs/required_test.rb +12 -0
  44. data/test/inputs/string_input_test.rb +10 -19
  45. data/test/inputs/text_input_test.rb +10 -3
  46. data/test/support/misc_helpers.rb +14 -1
  47. data/test/support/models.rb +11 -1
  48. data/test/test_helper.rb +9 -1
  49. metadata +25 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88d85494e222c13d302bed66c947ebc999702a46
4
- data.tar.gz: 6974cf74dc9cada33d515c0125c4506262aa4118
3
+ metadata.gz: 9a6c95d6f9a46246e380928d9f811d32400b46af
4
+ data.tar.gz: a1b26b221855af2b653a28da26fec66041b1bfc2
5
5
  SHA512:
6
- metadata.gz: c2f1599b149fd691ccc0471af01e5f2f997465f55449bfea0924768c45f83510d36911342e54e8c42dfa75adf5da278261188f17c938b3571446b97c419e2011
7
- data.tar.gz: 4c1677e4c36aa1381a378ef3a2c688db1881089d014cb97078f14dd2f5000a618fddc9671f78663fd693c86e4bc8524f3f2c9837aa5e8f7707c9b07b223cf114
6
+ metadata.gz: 381db066326564168e6c9242682b3a699397f8b4dbb3bd2f3662f4f817b51c5f65c6fb3d58e8e1a5e50bed6fa86d62ab024557cd67b221829d900ac81f52df56
7
+ data.tar.gz: 0340f0e2604165e8b266afe34423e1a1dcfc9e86daf08a84d690f9192624d482a846ac83685f198497e6da75317bd70a95c16a77f9d31c783b4ede1e23da211d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,43 @@
1
- ## 3.1.0.rc2
1
+ ## 3.2.1
2
+
3
+ * Updated gem dependency to support Rails 5.0.x.
4
+
5
+ ## 3.2.0
6
+
7
+ ### bug fix
8
+ * Improve performance of input generation by disabling support for `_html` translations. This reverts the feature introduced on the 3.1.0 branch
9
+
10
+ ## 3.1.1
11
+
12
+ ### enhancements
13
+ * Add the `disabled_class` to the label when the input is disabled. [@rhodrid](https://github.com/rhodrid)
14
+
15
+ ### bug fix
16
+ * Make it possible to override `required` value that was previously set in the wrapper. [@nashby](https://github.com/nashby)
17
+
18
+ * `date/time/datetime` inputs now correctly generate the label `for` attribute when
19
+ HTML5 compatibility is explicitly enabled. [@ericsullivan](https://github.com/ericsullivan)
20
+
21
+ * The datetime, date, and time inputs now have a nice format by default on bootstrap.
22
+ [@ulissesalmeida](https://github.com/ulissesalmeida) [@eltonchrls](https://github.com/eltonchrls)
23
+
24
+ * Now it is possible to set custom input mappings for collections.
25
+
26
+ Example:
27
+
28
+ ```ruby
29
+ # On configuration:
30
+ config.input_mappings = { /gender$/ => :check_boxes }
31
+
32
+ # On form:
33
+ f.input :gender, collection: [:male, :female]
34
+ ```
35
+ [strangeworks](https://github.com/strangeworks)
36
+
37
+ ## 3.1.0
2
38
 
3
39
  ### enhancements
40
+ * Update foundation generator to version 5. [@jorge-d](https://github.com/jorge-d)
4
41
  * Add mapping to `uuid` columns.
5
42
  * Add custom namespaces for custom inputs feature. [@vala](https://github.com/vala)
6
43
  * Add `:unless_blank` option to the wrapper API. [@IanVaughan](https://github.com/IanVaughan)
@@ -27,8 +64,11 @@
27
64
  * Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
28
65
  * Add support to define custom error messages for the attributes.
29
66
  * Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
67
+ * The default form class can now be overridden with `html: { :class }`. [@rmm5t](https://github.com/rmm5t)
30
68
 
31
69
  ### bug fix
70
+ * Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
71
+ * Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
32
72
  * Collection input that uses automatic collection translation properly sets checked values.
33
73
  Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
34
74
  * Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
@@ -37,5 +77,9 @@
37
77
  ## deprecation
38
78
  * Methods on custom inputs now accept a required argument with the wrapper options.
39
79
  See https://github.com/plataformatec/simple_form/pull/997 for more information.
80
+ * SimpleForm.form_class is deprecated in favor of SimpleForm.default_form_class.
81
+ Future versions of Simple Form will not generate `simple_form` class for the form
82
+ element.
83
+ See https://github.com/plataformatec/simple_form/pull/1109 for more information.
40
84
 
41
85
  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-2014 Plataformatec http://plataformatec.com.br/
1
+ Copyright (c) 2009-2015 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
@@ -32,13 +32,6 @@ Run the generator:
32
32
  rails generate simple_form:install
33
33
  ```
34
34
 
35
- Also, if you want to use the country select, you will need the
36
- [country_select gem](https://rubygems.org/gems/country_select), add it to your Gemfile:
37
-
38
- ```ruby
39
- gem 'country_select'
40
- ```
41
-
42
35
  ### Bootstrap
43
36
 
44
37
  **Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/).
@@ -55,9 +48,9 @@ For more information see the generator output, our
55
48
  [example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
56
49
  [the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
57
50
 
58
- ### Zurb Foundation 3
51
+ ### Zurb Foundation 5
59
52
 
60
- To generate wrappers that are compatible with [Zurb Foundation 3](http://foundation.zurb.com/), pass
53
+ To generate wrappers that are compatible with [Zurb Foundation 5](http://foundation.zurb.com/), pass
61
54
  the `foundation` option to the generator, like this:
62
55
 
63
56
  ```console
@@ -68,7 +61,23 @@ Please note that the Foundation wrapper does not support the `:hint` option by d
68
61
  enable hints, please uncomment the appropriate line in `config/initializers/simple_form_foundation.rb`.
69
62
  You will need to provide your own CSS styles for hints.
70
63
 
71
- Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/old-docs/f3/rails.php).
64
+ Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/applications.html).
65
+
66
+ ### Country Select
67
+
68
+ If you want to use the country select, you will need the
69
+ [country_select gem](https://rubygems.org/gems/country_select), add it to your Gemfile:
70
+
71
+ ```ruby
72
+ gem 'country_select'
73
+ ```
74
+
75
+ If you don't want to use the gem you can easily override this behaviour by mapping the
76
+ country inputs to something else, with a line like this in your `simple_form.rb` initializer:
77
+
78
+ ```ruby
79
+ config.input_mappings = { /country/ => :string }
80
+ ```
72
81
 
73
82
  ## Usage
74
83
 
@@ -91,12 +100,12 @@ To start using **Simple Form** you just have to use the helper it provides:
91
100
  This will generate an entire form with labels for user name and password as well, and render errors
92
101
  by default when you render the form with invalid data (after submitting for example).
93
102
 
94
- You can overwrite the default label by passing it to the input method. You can also add a hint or
95
- even a placeholder. For boolean inputs, you can add an inline label as well:
103
+ You can overwrite the default label by passing it to the input method. You can also add a hint,
104
+ an error, or even a placeholder. For boolean inputs, you can add an inline label as well:
96
105
 
97
106
  ```erb
98
107
  <%= simple_form_for @user do |f| %>
99
- <%= f.input :username, label: 'Your username please' %>
108
+ <%= f.input :username, label: 'Your username please', error: 'Username is mandatory, please specify one' %>
100
109
  <%= f.input :password, hint: 'No special characters.' %>
101
110
  <%= f.input :email, placeholder: 'user@domain.com' %>
102
111
  <%= f.input :remember_me, inline_label: 'Yes, remember me' %>
@@ -259,7 +268,6 @@ end
259
268
  ```
260
269
 
261
270
  For check boxes and radio buttons you can remove the label changing `boolean_style` from default value `:nested` to `:inline`.
262
- Also, `item_wrapper_tag` will not work when `boolean_style` is set to `:nested`.
263
271
 
264
272
  Example:
265
273
 
@@ -319,8 +327,9 @@ translation. All other options given are sent straight to the underlying helper.
319
327
  can give prompt as:
320
328
 
321
329
  ```ruby
322
- f.input :age, collection: 18..60, prompt: "Select your age"
330
+ f.input :age, collection: 18..60, prompt: "Select your age", selected: 21
323
331
  ```
332
+ Extra options are passed into helper [`collection_select`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select).
324
333
 
325
334
  It is also possible to create grouped collection selects, that will use the html *optgroup* tags, like this:
326
335
 
@@ -404,7 +413,7 @@ The association helper just invokes `input` under the hood, so all options avail
404
413
  the collection by hand, all together with the prompt:
405
414
 
406
415
  ```ruby
407
- f.association :company, collection: Company.active.all(order: 'name'), prompt: "Choose a Company"
416
+ f.association :company, collection: Company.active.order(:name), prompt: "Choose a Company"
408
417
  ```
409
418
 
410
419
  In case you want to declare different labels and values:
@@ -429,6 +438,22 @@ All web forms need buttons, right? **Simple Form** wraps them in the DSL, acting
429
438
 
430
439
  The above will simply call submit. You choose to use it or not, it's just a question of taste.
431
440
 
441
+ The button method also accepts optional parameters, that are delegated to the underlying submit call:
442
+
443
+ ```erb
444
+ <%= f.button :submit, "Custom Button Text", class: "my-button" %>
445
+ ```
446
+
447
+ To create a `<button>` element, use the following syntax:
448
+
449
+ ```erb
450
+ <%= f.button :button, "Custom Button Text" %>
451
+
452
+ <%= f.button :button do %>
453
+ Custom Button Text
454
+ <% end %>
455
+ ```
456
+
432
457
  ### Wrapping Rails Form Helpers
433
458
 
434
459
  Say you wanted to use a rails form helper but still wrap it in **Simple Form** goodness? You can, by
@@ -455,7 +480,7 @@ Rails helper, but change the builder to use the `SimpleForm::FormBuilder`.
455
480
 
456
481
  ```ruby
457
482
  form_for @user do |f|
458
- simple_fields_for :posts do |posts_form|
483
+ f.simple_fields_for :posts do |posts_form|
459
484
  # Here you have all simple_form methods available
460
485
  posts_form.input :title
461
486
  end
@@ -547,7 +572,9 @@ that extends the string one, you just need to add this file:
547
572
  # app/inputs/currency_input.rb
548
573
  class CurrencyInput < SimpleForm::Inputs::Base
549
574
  def input(wrapper_options)
550
- "$ #{@builder.text_field(attribute_name, input_html_options)}".html_safe
575
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
576
+
577
+ "$ #{@builder.text_field(attribute_name, merged_input_options)}".html_safe
551
578
  end
552
579
  end
553
580
  ```
@@ -781,6 +808,22 @@ object itself. Thus, similarly, if a form for an `Admin::User` object is defined
781
808
  `simple_form_for @admin_user, as: :some_user`, **Simple Form** will look for translations
782
809
  under `some_user` instead of `admin_user`.
783
810
 
811
+ When translate `simple_fields_for` attributes be sure to use the same name you pass to it, e.g. `simple_fields_for :posts` should be placed under `posts` not `post`:
812
+
813
+ ```yaml
814
+ en:
815
+ simple_form:
816
+ labels:
817
+ posts:
818
+ title: 'Post title'
819
+ hints:
820
+ posts:
821
+ title: 'A good title'
822
+ placeholders:
823
+ posts:
824
+ title: 'Once upon a time...'
825
+ ```
826
+
784
827
  ## Configuration
785
828
 
786
829
  **Simple Form** has several configuration options. You can read and change them in the initializer
@@ -977,11 +1020,20 @@ You can also add `novalidate` to a specific form by setting the option on the fo
977
1020
  <%= simple_form_for(resource, html: { novalidate: true }) do |form| %>
978
1021
  ```
979
1022
 
980
- Please notice that any of the configurations above will not disable the `placeholder` component,
981
- which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute fine,
982
- and if they aren't, any plugin you use would take of using the placeholder attribute to do it.
983
- However, you can disable it if you want, by removing the placeholder component from the components
984
- list in **Simple Form** configuration file.
1023
+ Please notice that none of the configurations above will disable the `placeholder` component,
1024
+ which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute
1025
+ just fine, and if they aren't, any plugin you use would take care of applying the placeholder.
1026
+ In any case, you can disable it if you really want to, by removing the placeholder component
1027
+ from the components list in the **Simple Form** configuration file.
1028
+
1029
+ HTML 5 date / time inputs are not generated by **Simple Form** by default, so using `date`,
1030
+ `time` or `datetime` will all generate select boxes using normal Rails helpers. We believe
1031
+ browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis
1032
+ by passing the html5 option:
1033
+
1034
+ ```erb
1035
+ <%= f.input :expires_at, as: :date, html5: true %>
1036
+ ```
985
1037
 
986
1038
  ## Information
987
1039
 
@@ -1020,7 +1072,7 @@ https://github.com/plataformatec/simple_form/issues
1020
1072
 
1021
1073
  ## License
1022
1074
 
1023
- MIT License. Copyright 2009-2014 Plataformatec. http://plataformatec.com.br
1075
+ MIT License. Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
1024
1076
 
1025
1077
  You are not granted rights or licenses to the trademarks of the Plataformatec, including without
1026
1078
  limitation the Simple Form name or logo.
@@ -5,11 +5,11 @@ module SimpleForm
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
  class_option :template_engine, desc: 'Template engine to be invoked (erb, haml or slim).'
7
7
  class_option :bootstrap, type: :boolean, desc: 'Add the Bootstrap wrappers to the SimpleForm initializer.'
8
- class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
8
+ class_option :foundation, type: :boolean, desc: 'Add the Zurb Foundation 5 wrappers to the SimpleForm initializer.'
9
9
 
10
10
  def info_bootstrap
11
11
  return if options.bootstrap? || options.foundation?
12
- puts "SimpleForm 2 supports Bootstrap and Zurb Foundation 3. If you want "\
12
+ puts "SimpleForm 3 supports Bootstrap and Zurb Foundation 5. If you want "\
13
13
  "a configuration that is compatible with one of these frameworks, then please " \
14
14
  "re-run this generator with --bootstrap or --foundation as an option."
15
15
  end
@@ -90,8 +90,7 @@ SimpleForm.setup do |config|
90
90
  # config.collection_wrapper_class = nil
91
91
 
92
92
  # You can wrap each item in a collection of radio/check boxes with a tag,
93
- # defaulting to :span. Please note that when using :boolean_style = :nested,
94
- # SimpleForm will force this option to be a label.
93
+ # defaulting to :span.
95
94
  # config.item_wrapper_tag = :span
96
95
 
97
96
  # You can define a class to use in all item wrappers. Defaulting to none.
@@ -103,8 +102,9 @@ SimpleForm.setup do |config|
103
102
  # You can define the class to use on all labels. Default is nil.
104
103
  # config.label_class = nil
105
104
 
106
- # You can define the class to use on all forms. Default is simple_form.
107
- # config.form_class = :simple_form
105
+ # You can define the default class to be used on forms. Can be overriden
106
+ # with `html: { :class }`. Defaulting to none.
107
+ # config.default_form_class = nil
108
108
 
109
109
  # You can define which elements should obtain additional classes
110
110
  # config.generate_additional_classes_for = [:wrapper, :label, :input]
@@ -45,7 +45,8 @@ SimpleForm.setup do |config|
45
45
  config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
46
46
  b.use :html5
47
47
  b.optional :readonly
48
- b.use :label_input
48
+ b.use :label, class: 'control-label'
49
+ b.use :input
49
50
  b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
50
51
  b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
51
52
  end
@@ -86,7 +87,7 @@ SimpleForm.setup do |config|
86
87
 
87
88
  b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
88
89
  wr.wrapper tag: 'div', class: 'checkbox' do |ba|
89
- ba.use :label_input, class: 'col-sm-9'
90
+ ba.use :label_input
90
91
  end
91
92
 
92
93
  wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
@@ -121,9 +122,28 @@ SimpleForm.setup do |config|
121
122
  b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
122
123
  end
123
124
 
125
+ config.wrappers :multi_select, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
126
+ b.use :html5
127
+ b.optional :readonly
128
+ b.use :label, class: 'control-label'
129
+ b.wrapper tag: 'div', class: 'form-inline' do |ba|
130
+ ba.use :input, class: 'form-control'
131
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
132
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
133
+ end
134
+ end
124
135
  # Wrappers for forms and inputs using the Bootstrap toolkit.
125
136
  # Check the Bootstrap docs (http://getbootstrap.com)
126
137
  # to learn about the different styles for forms and inputs,
127
138
  # buttons and other elements.
128
139
  config.default_wrapper = :vertical_form
140
+ config.wrapper_mappings = {
141
+ check_boxes: :vertical_radio_and_checkboxes,
142
+ radio_buttons: :vertical_radio_and_checkboxes,
143
+ file: :vertical_file_input,
144
+ boolean: :vertical_boolean,
145
+ datetime: :multi_select,
146
+ date: :multi_select,
147
+ time: :multi_select
148
+ }
129
149
  end
@@ -1,6 +1,13 @@
1
1
  # Use this setup block to configure all options available in SimpleForm.
2
2
  SimpleForm.setup do |config|
3
- config.wrappers :foundation, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
3
+ # Don't forget to edit this file to adapt it to your needs (specially
4
+ # all the grid-related classes)
5
+ #
6
+ # Please note that hints are commented out by default since Foundation
7
+ # does't provide styles for hints. You will need to provide your own CSS styles for hints.
8
+ # Uncomment them to enable hints.
9
+
10
+ config.wrappers :vertical_form, class: :input, hint_class: :field_with_hint, error_class: :error do |b|
4
11
  b.use :html5
5
12
  b.use :placeholder
6
13
  b.optional :maxlength
@@ -10,17 +17,91 @@ SimpleForm.setup do |config|
10
17
  b.use :label_input
11
18
  b.use :error, wrap_with: { tag: :small, class: :error }
12
19
 
13
- # Uncomment the following line to enable hints. The line is commented out by default since Foundation
14
- # does't provide styles for hints. You will need to provide your own CSS styles for hints.
20
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
21
+ end
22
+
23
+ config.wrappers :horizontal_form, tag: 'div', class: 'row', hint_class: :field_with_hint, error_class: :error do |b|
24
+ b.use :html5
25
+ b.use :placeholder
26
+ b.optional :maxlength
27
+ b.optional :pattern
28
+ b.optional :min_max
29
+ b.optional :readonly
30
+
31
+ b.wrapper :label_wrapper, tag: :div, class: 'small-3 columns' do |ba|
32
+ ba.use :label, class: 'right inline'
33
+ end
34
+
35
+ b.wrapper :right_input_wrapper, tag: :div, class: 'small-9 columns' do |ba|
36
+ ba.use :input
37
+ ba.use :error, wrap_with: { tag: :small, class: :error }
38
+ # ba.use :hint, wrap_with: { tag: :span, class: :hint }
39
+ end
40
+ end
41
+
42
+ config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'row' do |b|
43
+ b.use :html5
44
+ b.optional :readonly
45
+
46
+ b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
47
+ ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
48
+ bb.use :input
49
+ bb.use :label_text
50
+ end
51
+
52
+ ba.use :error, wrap_with: { tag: :small, class: :error }
53
+ # ba.use :hint, wrap_with: { tag: :span, class: :hint }
54
+ end
55
+ end
56
+
57
+ # Foundation does not provide a way to handle inline forms
58
+ # This wrapper can be used to create an inline form
59
+ # by hiding that labels on every screen sizes ('hidden-for-small-up').
60
+ #
61
+ # Note that you need to adapt this wrapper to your needs. If you need a 4
62
+ # columns form then change the wrapper class to 'small-3', if you need
63
+ # only two use 'small-6' and so on.
64
+ config.wrappers :inline_form, tag: 'div', class: 'column small-4', hint_class: :field_with_hint, error_class: :error do |b|
65
+ b.use :html5
66
+ b.use :placeholder
67
+ b.optional :maxlength
68
+ b.optional :pattern
69
+ b.optional :min_max
70
+ b.optional :readonly
71
+
72
+ b.use :label, class: 'hidden-for-small-up'
73
+ b.use :input
74
+
75
+ b.use :error, wrap_with: { tag: :small, class: :error }
76
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
77
+ end
78
+
79
+ # Examples of use:
80
+ # - wrapper_html: {class: 'row'}, custom_wrapper_html: {class: 'column small-12'}
81
+ # - custom_wrapper_html: {class: 'column small-3 end'}
82
+ config.wrappers :customizable_wrapper, tag: 'div', error_class: :error do |b|
83
+ b.use :html5
84
+ b.optional :readonly
85
+
86
+ b.wrapper :custom_wrapper, tag: :div do |ba|
87
+ ba.use :label_input
88
+ end
89
+
90
+ b.use :error, wrap_with: { tag: :small, class: :error }
15
91
  # b.use :hint, wrap_with: { tag: :span, class: :hint }
16
92
  end
17
93
 
18
94
  # CSS class for buttons
19
95
  config.button_class = 'button'
20
96
 
97
+ # Set this to div to make the checkbox and radio properly work
98
+ # otherwise simple_form adds a label tag instead of a div arround
99
+ # the nested label
100
+ config.item_wrapper_tag = :div
101
+
21
102
  # CSS class to add for error notification helper.
22
103
  config.error_notification_class = 'alert-box alert'
23
104
 
24
105
  # The default wrapper to be used by the FormBuilder.
25
- config.default_wrapper = :foundation
106
+ config.default_wrapper = :vertical_form
26
107
  end
@@ -17,6 +17,7 @@ module SimpleForm
17
17
  options = args.extract_options!
18
18
  options[:wrapper] = self.options[:wrapper] if options[:wrapper].nil?
19
19
  options[:defaults] ||= self.options[:defaults]
20
+ options[:wrapper_mappings] ||= self.options[:wrapper_mappings]
20
21
 
21
22
  if self.class < ActionView::Helpers::FormBuilder
22
23
  options[:builder] ||= self.class
@@ -16,7 +16,11 @@ module SimpleForm
16
16
  unless options[:html].key?(:novalidate)
17
17
  options[:html][:novalidate] = !SimpleForm.browser_validations
18
18
  end
19
- options[:html][:class] = [SimpleForm.form_class, simple_form_css_class(record, options)].compact.join(" ")
19
+ if options[:html].key?(:class)
20
+ options[:html][:class] = [SimpleForm.form_class, options[:html][:class]].compact
21
+ else
22
+ options[:html][:class] = [SimpleForm.form_class, SimpleForm.default_form_class, simple_form_css_class(record, options)].compact
23
+ end
20
24
 
21
25
  with_simple_form_field_error_proc do
22
26
  form_for(record, options, &block)
@@ -18,13 +18,11 @@ module SimpleForm
18
18
  def error_text
19
19
  text = has_custom_error? ? options[:error] : errors.send(error_method)
20
20
 
21
- "#{html_escape(options[:error_prefix])} #{text}".lstrip.html_safe
21
+ "#{html_escape(options[:error_prefix])} #{html_escape(text)}".lstrip.html_safe
22
22
  end
23
23
 
24
24
  def full_error_text
25
- text = has_custom_error? ? options[:error] : full_errors.send(error_method)
26
-
27
- text.html_safe
25
+ has_custom_error? ? options[:error] : full_errors.send(error_method)
28
26
  end
29
27
 
30
28
  def error_method
@@ -52,7 +50,7 @@ module SimpleForm
52
50
  end
53
51
 
54
52
  def full_errors_on_association
55
- reflection ? object.full_messages_for(reflection.name) : []
53
+ reflection ? object.errors.full_messages_for(reflection.name) : []
56
54
  end
57
55
 
58
56
  def has_custom_error?
@@ -7,10 +7,10 @@ module SimpleForm
7
7
 
8
8
  def html5(wrapper_options = nil)
9
9
  @html5 = true
10
- if has_required?
11
- input_html_options[:required] = true
12
- input_html_options[:'aria-required'] = true
13
- end
10
+
11
+ input_html_options[:required] = has_required?
12
+ input_html_options[:'aria-required'] = has_required? || nil
13
+
14
14
  nil
15
15
  end
16
16
 
@@ -42,7 +42,7 @@ module SimpleForm
42
42
 
43
43
  def label_html_options
44
44
  label_html_classes = SimpleForm.additional_classes_for(:label) {
45
- [input_type, required_class, SimpleForm.label_class].compact
45
+ [input_type, required_class, disabled_class, SimpleForm.label_class].compact
46
46
  }
47
47
 
48
48
  label_options = html_options_for(:label, label_html_classes)
@@ -30,6 +30,7 @@ module SimpleForm
30
30
  map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput
31
31
  map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput
32
32
  map_type :boolean, to: SimpleForm::Inputs::BooleanInput
33
+ map_type :hidden, to: SimpleForm::Inputs::HiddenInput
33
34
 
34
35
  def self.discovery_cache
35
36
  @discovery_cache ||= {}
@@ -131,14 +132,15 @@ module SimpleForm
131
132
  # name="user[name]" type="text" value="Carlos" />
132
133
  #
133
134
  def input_field(attribute_name, options = {})
135
+ components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)
136
+
134
137
  options = options.dup
135
- options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *ATTRIBUTE_COMPONENTS)
138
+ options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *components)
136
139
  options = @defaults.deep_dup.deep_merge(options) if @defaults
137
140
 
138
141
  input = find_input(attribute_name, options)
139
142
  wrapper = find_wrapper(input.input_type, options)
140
- components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS) + [:input]
141
- components = components.map { |component| SimpleForm::Wrappers::Leaf.new(component) }
143
+ components = components.concat([:input]).map { |component| SimpleForm::Wrappers::Leaf.new(component) }
142
144
 
143
145
  SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
144
146
  end
@@ -205,8 +207,8 @@ module SimpleForm
205
207
  options = args.extract_options!.dup
206
208
  options[:class] = [SimpleForm.button_class, options[:class]].compact
207
209
  args << options
208
- if respond_to?("#{type}_button")
209
- send("#{type}_button", *args, &block)
210
+ if respond_to?(:"#{type}_button")
211
+ send(:"#{type}_button", *args, &block)
210
212
  else
211
213
  send(type, *args, &block)
212
214
  end
@@ -507,8 +509,8 @@ module SimpleForm
507
509
  # collection is given.
508
510
  def default_input_type(attribute_name, column, options)
509
511
  return options[:as].to_sym if options[:as]
510
- return :select if options[:collection]
511
512
  custom_type = find_custom_type(attribute_name.to_s) and return custom_type
513
+ return :select if options[:collection]
512
514
 
513
515
  input_type = column.try(:type)
514
516
  case input_type
@@ -542,7 +544,7 @@ module SimpleForm
542
544
  end
543
545
 
544
546
  def find_attribute_column(attribute_name)
545
- if @object.respond_to?(:column_for_attribute)
547
+ if @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name)
546
548
  @object.column_for_attribute(attribute_name)
547
549
  end
548
550
  end
@@ -178,17 +178,13 @@ module SimpleForm
178
178
  model_names.shift
179
179
 
180
180
  lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
181
- lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}_html"
182
181
  lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
183
- lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}_html"
184
182
  end
185
183
  lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}"
186
- lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}_html"
187
184
  lookups << :"defaults.#{reflection_or_attribute_name}"
188
- lookups << :"defaults.#{reflection_or_attribute_name}_html"
189
185
  lookups << default
190
186
 
191
- t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
187
+ I18n.t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
192
188
  end
193
189
 
194
190
  def merge_wrapper_options(options, wrapper_options)
@@ -41,7 +41,7 @@ module SimpleForm
41
41
  # which won't generate the hidden checkbox. This is the default functionality
42
42
  # in Rails > 3.2.1, and is backported in SimpleForm AV helpers.
43
43
  def build_check_box(unchecked_value, options)
44
- @builder.check_box(attribute_name, input_html_options, checked_value, unchecked_value)
44
+ @builder.check_box(attribute_name, options, checked_value, unchecked_value)
45
45
  end
46
46
 
47
47
  # Build a checkbox without generating the hidden field. See
@@ -21,10 +21,8 @@ module SimpleForm
21
21
  options = super
22
22
 
23
23
  options[:include_blank] = true unless skip_include_blank?
24
-
25
- [:prompt, :include_blank].each do |key|
26
- translate_option options, key
27
- end
24
+ translate_option options, :prompt
25
+ translate_option options, :include_blank
28
26
 
29
27
  options
30
28
  end
@@ -6,7 +6,7 @@ module SimpleForm
6
6
 
7
7
  merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
8
8
 
9
- @builder.send("collection_#{input_type}",
9
+ @builder.send(:"collection_#{input_type}",
10
10
  attribute_name, collection, value_method, label_method,
11
11
  input_options, merged_input_options,
12
12
  &collection_block_for_nested_boolean_style