simple_form 3.1.0.rc2 → 3.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -1
- data/MIT-LICENSE +1 -1
- data/README.md +76 -24
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +4 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +22 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
- data/lib/simple_form/action_view_extensions/builder.rb +1 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +5 -1
- data/lib/simple_form/components/errors.rb +3 -5
- data/lib/simple_form/components/html5.rb +4 -4
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +9 -7
- data/lib/simple_form/inputs/boolean_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +1 -1
- data/lib/simple_form/inputs/date_time_input.rb +12 -8
- data/lib/simple_form/tags.rb +2 -4
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form.rb +13 -2
- data/test/action_view_extensions/builder_test.rb +31 -31
- data/test/action_view_extensions/form_helper_test.rb +20 -1
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +37 -37
- data/test/form_builder/button_test.rb +5 -5
- data/test/form_builder/error_test.rb +75 -16
- data/test/form_builder/general_test.rb +42 -11
- data/test/form_builder/hint_test.rb +3 -3
- data/test/form_builder/input_field_test.rb +59 -53
- data/test/form_builder/label_test.rb +13 -3
- data/test/form_builder/wrapper_test.rb +29 -14
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +9 -1
- data/test/inputs/collection_check_boxes_input_test.rb +22 -0
- data/test/inputs/collection_radio_buttons_input_test.rb +25 -3
- data/test/inputs/collection_select_input_test.rb +17 -17
- data/test/inputs/datetime_input_test.rb +6 -1
- data/test/inputs/grouped_collection_select_input_test.rb +8 -8
- data/test/inputs/numeric_input_test.rb +19 -19
- data/test/inputs/priority_input_test.rb +6 -6
- data/test/inputs/required_test.rb +12 -0
- data/test/inputs/string_input_test.rb +10 -10
- data/test/inputs/text_input_test.rb +10 -3
- data/test/support/misc_helpers.rb +14 -1
- data/test/support/models.rb +11 -1
- data/test/test_helper.rb +9 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e30c2408e03c6ec8e50e4c96eb6b6ed2496c2c17
|
|
4
|
+
data.tar.gz: 324665062b839154b5c7b2c2fd8d2a603466c854
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1b58ac3394c6237e862f81de9eae3c8511d72a27f3e65ec4c11929f6e30f52378ff325a5c7a336f18015d5707f8bce061e797c264b8fc4a15b95e653f1c8613c
|
|
7
|
+
data.tar.gz: 81e743325007ec095390aac7762bfe62c7ac5e0f1650a133db3834faa8303931b6e287acf5f4ed191241e3d50b9afa1d0aeba68dc43c6d0ae4229fdd27a1b94d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
|
-
##
|
|
1
|
+
## master
|
|
2
|
+
|
|
3
|
+
## enhancements
|
|
4
|
+
|
|
5
|
+
## bug fix
|
|
6
|
+
|
|
7
|
+
## 3.1.1
|
|
8
|
+
|
|
9
|
+
### enhancements
|
|
10
|
+
* Add the `disabled_class` to the label when the input is disabled. [@rhodrid](https://github.com/rhodrid)
|
|
11
|
+
|
|
12
|
+
### bug fix
|
|
13
|
+
* Make it possible to override `required` value that was previously set in the wrapper. [@nashby](https://github.com/nashby)
|
|
14
|
+
|
|
15
|
+
* `date/time/datetime` inputs now correctly generate the label `for` attribute when
|
|
16
|
+
HTML5 compatibility is explicitly enabled. [@ericsullivan](https://github.com/ericsullivan)
|
|
17
|
+
|
|
18
|
+
* The datetime, date, and time inputs now have a nice format by default on bootstrap.
|
|
19
|
+
[ulissesalmeida](https://github.com/ulissesalmeida) [eltonchrls](https://github.com/eltonchrls)
|
|
20
|
+
|
|
21
|
+
* Now it is possible to set custom input mappings for collections.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
# On configuration:
|
|
27
|
+
config.input_mappings = { /gender$/ => :check_boxes }
|
|
28
|
+
|
|
29
|
+
# On form:
|
|
30
|
+
f.input :gender, collection: [:male, :female]
|
|
31
|
+
```
|
|
32
|
+
[strangeworks](https://github.com/strangeworks)
|
|
33
|
+
|
|
34
|
+
## 3.1.0
|
|
2
35
|
|
|
3
36
|
### enhancements
|
|
37
|
+
* Update foundation generator to version 5. [@jorge-d](https://github.com/jorge-d)
|
|
4
38
|
* Add mapping to `uuid` columns.
|
|
5
39
|
* Add custom namespaces for custom inputs feature. [@vala](https://github.com/vala)
|
|
6
40
|
* Add `:unless_blank` option to the wrapper API. [@IanVaughan](https://github.com/IanVaughan)
|
|
@@ -27,8 +61,11 @@
|
|
|
27
61
|
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
|
|
28
62
|
* Add support to define custom error messages for the attributes.
|
|
29
63
|
* Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
|
|
64
|
+
* The default form class can now be overridden with `html: { :class }`. [@rmm5t](https://github.com/rmm5t)
|
|
30
65
|
|
|
31
66
|
### bug fix
|
|
67
|
+
* Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
|
|
68
|
+
* Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
|
|
32
69
|
* Collection input that uses automatic collection translation properly sets checked values.
|
|
33
70
|
Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
|
|
34
71
|
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
|
@@ -37,5 +74,9 @@
|
|
|
37
74
|
## deprecation
|
|
38
75
|
* Methods on custom inputs now accept a required argument with the wrapper options.
|
|
39
76
|
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
77
|
+
* SimpleForm.form_class is deprecated in favor of SimpleForm.default_form_class.
|
|
78
|
+
Future versions of Simple Form will not generate `simple_form` class for the form
|
|
79
|
+
element.
|
|
80
|
+
See https://github.com/plataformatec/simple_form/pull/1109 for more information.
|
|
40
81
|
|
|
41
82
|
Please check [v3.0](https://github.com/plataformatec/simple_form/blob/v3.0/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2009-
|
|
1
|
+
Copyright (c) 2009-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
|
|
51
|
+
### Zurb Foundation 5
|
|
59
52
|
|
|
60
|
-
To generate wrappers that are compatible with [Zurb Foundation
|
|
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/
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
|
981
|
-
which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute
|
|
982
|
-
and if they aren't, any plugin you use would take of
|
|
983
|
-
|
|
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-
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
107
|
-
#
|
|
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 :
|
|
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
|
|
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
|
-
|
|
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
|
-
#
|
|
14
|
-
|
|
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 = :
|
|
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]
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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, *
|
|
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 =
|
|
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
|
|
@@ -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,
|
|
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
|
-
|
|
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
|