simple_form 3.1.0.rc1 → 3.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +64 -16
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +9 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -15
- 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/labels.rb +1 -1
- data/lib/simple_form/form_builder.rb +34 -19
- data/lib/simple_form/inputs/boolean_input.rb +8 -5
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/tags.rb +3 -4
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +2 -2
- data/lib/simple_form/wrappers/many.rb +1 -0
- data/lib/simple_form.rb +21 -2
- data/test/action_view_extensions/builder_test.rb +34 -34
- data/test/action_view_extensions/form_helper_test.rb +33 -14
- data/test/components/label_test.rb +36 -36
- data/test/form_builder/association_test.rb +41 -41
- data/test/form_builder/button_test.rb +10 -10
- data/test/form_builder/error_test.rb +88 -29
- data/test/form_builder/general_test.rb +89 -64
- data/test/form_builder/hint_test.rb +18 -18
- data/test/form_builder/input_field_test.rb +59 -19
- data/test/form_builder/label_test.rb +23 -14
- data/test/form_builder/wrapper_test.rb +70 -21
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +17 -9
- data/test/inputs/collection_check_boxes_input_test.rb +46 -7
- data/test/inputs/collection_radio_buttons_input_test.rb +65 -26
- data/test/inputs/collection_select_input_test.rb +62 -62
- data/test/inputs/datetime_input_test.rb +24 -24
- data/test/inputs/disabled_test.rb +15 -15
- data/test/inputs/discovery_test.rb +44 -5
- data/test/inputs/file_input_test.rb +2 -2
- data/test/inputs/general_test.rb +20 -20
- data/test/inputs/grouped_collection_select_input_test.rb +10 -10
- data/test/inputs/hidden_input_test.rb +4 -4
- data/test/inputs/numeric_input_test.rb +43 -43
- data/test/inputs/priority_input_test.rb +13 -13
- data/test/inputs/readonly_test.rb +19 -19
- data/test/inputs/required_test.rb +13 -13
- data/test/inputs/string_input_test.rb +33 -33
- data/test/inputs/text_input_test.rb +7 -7
- data/test/support/discovery_inputs.rb +20 -0
- data/test/support/misc_helpers.rb +28 -0
- data/test/support/models.rb +13 -2
- data/test/test_helper.rb +5 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 275599af691b7ba0bd40146940b8936b7b00bb65
|
|
4
|
+
data.tar.gz: bf12768bc9960272a7823e62276f8191a5b293d7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f62bec40ad89719416a5010cd0ec3eab18a6322289cd817e732061d4b53dd01e6f749a3a1a89caabe2fa233749d9841dea374365572fa91f8dc70755382d6811
|
|
7
|
+
data.tar.gz: 82930fed0d675a74d7e226ebf39e78ebf86807ba583988959be4f633c50f76e3cbc2e2b924d243ce87e5423089610962dab3f1795eb242ce544d985d702c8f36
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
## 3.1.0
|
|
1
|
+
## 3.1.0
|
|
2
2
|
|
|
3
3
|
### enhancements
|
|
4
|
+
* Update foundation generator to version 5. [@jorge-d](https://github.com/jorge-d)
|
|
5
|
+
* Add mapping to `uuid` columns.
|
|
6
|
+
* Add custom namespaces for custom inputs feature. [@vala](https://github.com/vala)
|
|
7
|
+
* Add `:unless_blank` option to the wrapper API. [@IanVaughan](https://github.com/IanVaughan)
|
|
4
8
|
* Add support to html markup in the I18n options. [@laurocaetano](https://github.com/laurocaetano)
|
|
5
9
|
* Add the `full_error` component. [@laurocaetano](https://github.com/laurocaetano)
|
|
6
10
|
* Add support to `scope` to be used on associations. [@laurocaetano](https://github.com/laurocaetano)
|
|
@@ -24,8 +28,11 @@
|
|
|
24
28
|
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
|
|
25
29
|
* Add support to define custom error messages for the attributes.
|
|
26
30
|
* Add support to change the I18n scope to be used in Simple Form. [@nielsbuus](https://github.com/nielsbuus)
|
|
31
|
+
* The default form class can now be overridden with `html: { :class }`. [@rmm5t](https://github.com/rmm5t)
|
|
27
32
|
|
|
28
33
|
### bug fix
|
|
34
|
+
* Fix `full_error` when the attribute is an association. [@mvdamme](https://github.com/jorge-d)
|
|
35
|
+
* Fix suppport to `:namespace` and `:index` options for nested check boxes and radio buttons when the attribute is an association.
|
|
29
36
|
* Collection input that uses automatic collection translation properly sets checked values.
|
|
30
37
|
Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
|
|
31
38
|
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
|
@@ -34,5 +41,9 @@
|
|
|
34
41
|
## deprecation
|
|
35
42
|
* Methods on custom inputs now accept a required argument with the wrapper options.
|
|
36
43
|
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
44
|
+
* SimpleForm.form_class is deprecated in favor of SimpleForm.default_form_class.
|
|
45
|
+
Future versions of Simple Form will not generate `simple_form` class for the form
|
|
46
|
+
element.
|
|
47
|
+
See https://github.com/plataformatec/simple_form/pull/1109 for more information.
|
|
37
48
|
|
|
38
49
|
Please check [v3.0](https://github.com/plataformatec/simple_form/blob/v3.0/CHANGELOG.md) for previous changes.
|
data/README.md
CHANGED
|
@@ -55,9 +55,9 @@ For more information see the generator output, our
|
|
|
55
55
|
[example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
|
|
56
56
|
[the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
|
|
57
57
|
|
|
58
|
-
### Zurb Foundation
|
|
58
|
+
### Zurb Foundation 5
|
|
59
59
|
|
|
60
|
-
To generate wrappers that are compatible with [Zurb Foundation
|
|
60
|
+
To generate wrappers that are compatible with [Zurb Foundation 5](http://foundation.zurb.com/), pass
|
|
61
61
|
the `foundation` option to the generator, like this:
|
|
62
62
|
|
|
63
63
|
```console
|
|
@@ -68,7 +68,7 @@ Please note that the Foundation wrapper does not support the `:hint` option by d
|
|
|
68
68
|
enable hints, please uncomment the appropriate line in `config/initializers/simple_form_foundation.rb`.
|
|
69
69
|
You will need to provide your own CSS styles for hints.
|
|
70
70
|
|
|
71
|
-
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/
|
|
71
|
+
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/applications.html).
|
|
72
72
|
|
|
73
73
|
## Usage
|
|
74
74
|
|
|
@@ -259,7 +259,7 @@ end
|
|
|
259
259
|
```
|
|
260
260
|
|
|
261
261
|
For check boxes and radio buttons you can remove the label changing `boolean_style` from default value `:nested` to `:inline`.
|
|
262
|
-
Also, `
|
|
262
|
+
Also, `item_wrapper_tag` will not work when `boolean_style` is set to `:nested`.
|
|
263
263
|
|
|
264
264
|
Example:
|
|
265
265
|
|
|
@@ -429,6 +429,12 @@ All web forms need buttons, right? **Simple Form** wraps them in the DSL, acting
|
|
|
429
429
|
|
|
430
430
|
The above will simply call submit. You choose to use it or not, it's just a question of taste.
|
|
431
431
|
|
|
432
|
+
The button method also accepts optional parameters, that are delegated to the underlying submit call:
|
|
433
|
+
|
|
434
|
+
```erb
|
|
435
|
+
<%= f.button :submit, "Custom Button Text", class: "my-button" %>
|
|
436
|
+
```
|
|
437
|
+
|
|
432
438
|
### Wrapping Rails Form Helpers
|
|
433
439
|
|
|
434
440
|
Say you wanted to use a rails form helper but still wrap it in **Simple Form** goodness? You can, by
|
|
@@ -455,7 +461,7 @@ Rails helper, but change the builder to use the `SimpleForm::FormBuilder`.
|
|
|
455
461
|
|
|
456
462
|
```ruby
|
|
457
463
|
form_for @user do |f|
|
|
458
|
-
simple_fields_for :posts do |posts_form|
|
|
464
|
+
f.simple_fields_for :posts do |posts_form|
|
|
459
465
|
# Here you have all simple_form methods available
|
|
460
466
|
posts_form.input :title
|
|
461
467
|
end
|
|
@@ -521,6 +527,7 @@ specifying the helper method in the column `Mapping` as the `as:` option.
|
|
|
521
527
|
`tel` | `input[type=tel]` | `string` with `name =~ /phone/`
|
|
522
528
|
`password` | `input[type=password]` | `string` with `name =~ /password/`
|
|
523
529
|
`search` | `input[type=search]` | -
|
|
530
|
+
`uuid` | `input[type=text]` | `uuid`
|
|
524
531
|
`text` | `textarea` | `text`
|
|
525
532
|
`file` | `input[type=file]` | `string` responding to file methods
|
|
526
533
|
`hidden` | `input[type=hidden]` | -
|
|
@@ -546,7 +553,9 @@ that extends the string one, you just need to add this file:
|
|
|
546
553
|
# app/inputs/currency_input.rb
|
|
547
554
|
class CurrencyInput < SimpleForm::Inputs::Base
|
|
548
555
|
def input(wrapper_options)
|
|
549
|
-
|
|
556
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
|
557
|
+
|
|
558
|
+
"$ #{@builder.text_field(attribute_name, merged_input_options)}".html_safe
|
|
550
559
|
end
|
|
551
560
|
end
|
|
552
561
|
```
|
|
@@ -581,6 +590,28 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
|
|
581
590
|
end
|
|
582
591
|
```
|
|
583
592
|
|
|
593
|
+
If needed, you can namespace your custom inputs in a module and tell **Simple Form** to look for
|
|
594
|
+
their definitions in this module. This can avoid conflicts with other form libraries (like Formtastic) that look up
|
|
595
|
+
the global context to find inputs definition too.
|
|
596
|
+
|
|
597
|
+
```ruby
|
|
598
|
+
# app/inputs/custom_inputs/numeric_input
|
|
599
|
+
module CustomInputs
|
|
600
|
+
class NumericInput < SimpleForm::Inputs::NumericInput
|
|
601
|
+
def input_html_classes
|
|
602
|
+
super.push('no-spinner')
|
|
603
|
+
end
|
|
604
|
+
end
|
|
605
|
+
end
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
And in the **SimpleForm** initializer :
|
|
609
|
+
|
|
610
|
+
```ruby
|
|
611
|
+
# config/simple_form.rb
|
|
612
|
+
config.custom_inputs_namespaces << "CustomInputs"
|
|
613
|
+
```
|
|
614
|
+
|
|
584
615
|
## Custom form builder
|
|
585
616
|
|
|
586
617
|
You can create a custom form builder that uses **Simple Form**.
|
|
@@ -599,8 +630,7 @@ Create a form builder class that inherits from `SimpleForm::FormBuilder`.
|
|
|
599
630
|
```ruby
|
|
600
631
|
class CustomFormBuilder < SimpleForm::FormBuilder
|
|
601
632
|
def input(attribute_name, options = {}, &block)
|
|
602
|
-
options
|
|
603
|
-
super
|
|
633
|
+
super(attribute_name, options.merge(label: false), &block)
|
|
604
634
|
end
|
|
605
635
|
end
|
|
606
636
|
```
|
|
@@ -629,8 +659,8 @@ en:
|
|
|
629
659
|
user:
|
|
630
660
|
age: 'Rather not say'
|
|
631
661
|
prompts:
|
|
632
|
-
|
|
633
|
-
|
|
662
|
+
user:
|
|
663
|
+
gender: 'Select your gender'
|
|
634
664
|
```
|
|
635
665
|
|
|
636
666
|
And your forms will use this information to render the components for you.
|
|
@@ -896,6 +926,15 @@ end
|
|
|
896
926
|
By setting it as `optional`, a hint will only be generated when `hint: true` is explicitly used.
|
|
897
927
|
The same for placeholder.
|
|
898
928
|
|
|
929
|
+
It is also possible to give the option `:unless_blank` to the wrapper if you want to render it only
|
|
930
|
+
when the content is present.
|
|
931
|
+
|
|
932
|
+
```ruby
|
|
933
|
+
b.wrapper tag: :span, class: 'hint', unless_blank: true do |component|
|
|
934
|
+
component.optional :hint
|
|
935
|
+
end
|
|
936
|
+
```
|
|
937
|
+
|
|
899
938
|
## HTML 5 Notice
|
|
900
939
|
|
|
901
940
|
By default, **Simple Form** will generate input field types and attributes that are supported in HTML5,
|
|
@@ -946,11 +985,20 @@ You can also add `novalidate` to a specific form by setting the option on the fo
|
|
|
946
985
|
<%= simple_form_for(resource, html: { novalidate: true }) do |form| %>
|
|
947
986
|
```
|
|
948
987
|
|
|
949
|
-
Please notice that
|
|
950
|
-
which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute
|
|
951
|
-
and if they aren't, any plugin you use would take of
|
|
952
|
-
|
|
953
|
-
list in **Simple Form** configuration file.
|
|
988
|
+
Please notice that none of the configurations above will disable the `placeholder` component,
|
|
989
|
+
which is an HTML 5 feature. We believe most of the newest browsers are handling this attribute
|
|
990
|
+
just fine, and if they aren't, any plugin you use would take care of applying the placeholder.
|
|
991
|
+
In any case, you can disable it if you really want to, by removing the placeholder component
|
|
992
|
+
from the components list in the **Simple Form** configuration file.
|
|
993
|
+
|
|
994
|
+
HTML 5 date / time inputs are not generated by **Simple Form** by default, so using `date`,
|
|
995
|
+
`time` or `datetime` will all generate select boxes using normal Rails helpers. We believe
|
|
996
|
+
browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis
|
|
997
|
+
by passing the html5 option:
|
|
998
|
+
|
|
999
|
+
```erb
|
|
1000
|
+
<%= f.input :expires_at, as: :date, html5: true %>
|
|
1001
|
+
```
|
|
954
1002
|
|
|
955
1003
|
## Information
|
|
956
1004
|
|
|
@@ -985,7 +1033,7 @@ https://github.com/plataformatec/simple_form/issues
|
|
|
985
1033
|
[](http://badge.fury.io/rb/simple_form)
|
|
986
1034
|
[](http://travis-ci.org/plataformatec/simple_form)
|
|
987
1035
|
[](https://codeclimate.com/github/plataformatec/simple_form)
|
|
988
|
-
[](http://inch-ci.org/github/plataformatec/simple_form)
|
|
989
1037
|
|
|
990
1038
|
## License
|
|
991
1039
|
|
|
@@ -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
|
|
@@ -22,9 +22,9 @@ SimpleForm.setup do |config|
|
|
|
22
22
|
b.use :placeholder
|
|
23
23
|
|
|
24
24
|
## Optional extensions
|
|
25
|
-
# They are disabled unless you pass `f.input EXTENSION_NAME =>
|
|
25
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => true`
|
|
26
26
|
# to the input. If so, they will retrieve the values from the model
|
|
27
|
-
# if any exists. If you want to enable
|
|
27
|
+
# if any exists. If you want to enable any of those
|
|
28
28
|
# extensions by default, you can change `b.optional` to `b.use`.
|
|
29
29
|
|
|
30
30
|
# Calculates maxlength from length validations for string inputs
|
|
@@ -103,8 +103,9 @@ SimpleForm.setup do |config|
|
|
|
103
103
|
# You can define the class to use on all labels. Default is nil.
|
|
104
104
|
# config.label_class = nil
|
|
105
105
|
|
|
106
|
-
# You can define the class to
|
|
107
|
-
#
|
|
106
|
+
# You can define the default class to be used on forms. Can be overriden
|
|
107
|
+
# with `html: { :class }`. Defaulting to none.
|
|
108
|
+
# config.default_form_class = nil
|
|
108
109
|
|
|
109
110
|
# You can define which elements should obtain additional classes
|
|
110
111
|
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
|
@@ -131,6 +132,10 @@ SimpleForm.setup do |config|
|
|
|
131
132
|
# type as key and the wrapper that will be used for all inputs with specified type.
|
|
132
133
|
# config.wrapper_mappings = { string: :prepend }
|
|
133
134
|
|
|
135
|
+
# Namespaces where SimpleForm should look for custom input classes that
|
|
136
|
+
# override default inputs.
|
|
137
|
+
# config.custom_inputs_namespaces << "CustomInputs"
|
|
138
|
+
|
|
134
139
|
# Default priority for time_zone inputs.
|
|
135
140
|
# config.time_zone_priority = nil
|
|
136
141
|
|
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
# Use this setup block to configure all options available in SimpleForm.
|
|
2
2
|
SimpleForm.setup do |config|
|
|
3
|
+
config.error_notification_class = 'alert alert-danger'
|
|
3
4
|
config.button_class = 'btn btn-default'
|
|
4
5
|
config.boolean_label_class = nil
|
|
5
6
|
|
|
6
7
|
config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
7
8
|
b.use :html5
|
|
8
9
|
b.use :placeholder
|
|
10
|
+
b.optional :maxlength
|
|
11
|
+
b.optional :pattern
|
|
12
|
+
b.optional :min_max
|
|
13
|
+
b.optional :readonly
|
|
9
14
|
b.use :label, class: 'control-label'
|
|
10
15
|
|
|
11
|
-
b.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
15
|
-
end
|
|
16
|
+
b.use :input, class: 'form-control'
|
|
17
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
|
18
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
16
19
|
end
|
|
17
20
|
|
|
18
21
|
config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
19
22
|
b.use :html5
|
|
20
23
|
b.use :placeholder
|
|
24
|
+
b.optional :maxlength
|
|
25
|
+
b.optional :readonly
|
|
21
26
|
b.use :label, class: 'control-label'
|
|
22
27
|
|
|
23
|
-
b.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
27
|
-
end
|
|
28
|
+
b.use :input
|
|
29
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
|
30
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
31
34
|
b.use :html5
|
|
32
|
-
b.
|
|
35
|
+
b.optional :readonly
|
|
33
36
|
|
|
34
37
|
b.wrapper tag: 'div', class: 'checkbox' do |ba|
|
|
35
38
|
ba.use :label_input
|
|
@@ -41,8 +44,9 @@ SimpleForm.setup do |config|
|
|
|
41
44
|
|
|
42
45
|
config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
43
46
|
b.use :html5
|
|
44
|
-
b.
|
|
45
|
-
b.use :
|
|
47
|
+
b.optional :readonly
|
|
48
|
+
b.use :label, class: 'control-label'
|
|
49
|
+
b.use :input
|
|
46
50
|
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
|
47
51
|
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
48
52
|
end
|
|
@@ -50,6 +54,10 @@ SimpleForm.setup do |config|
|
|
|
50
54
|
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
51
55
|
b.use :html5
|
|
52
56
|
b.use :placeholder
|
|
57
|
+
b.optional :maxlength
|
|
58
|
+
b.optional :pattern
|
|
59
|
+
b.optional :min_max
|
|
60
|
+
b.optional :readonly
|
|
53
61
|
b.use :label, class: 'col-sm-3 control-label'
|
|
54
62
|
|
|
55
63
|
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
|
@@ -62,6 +70,8 @@ SimpleForm.setup do |config|
|
|
|
62
70
|
config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
63
71
|
b.use :html5
|
|
64
72
|
b.use :placeholder
|
|
73
|
+
b.optional :maxlength
|
|
74
|
+
b.optional :readonly
|
|
65
75
|
b.use :label, class: 'col-sm-3 control-label'
|
|
66
76
|
|
|
67
77
|
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
|
|
@@ -73,7 +83,7 @@ SimpleForm.setup do |config|
|
|
|
73
83
|
|
|
74
84
|
config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
75
85
|
b.use :html5
|
|
76
|
-
b.
|
|
86
|
+
b.optional :readonly
|
|
77
87
|
|
|
78
88
|
b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
|
|
79
89
|
wr.wrapper tag: 'div', class: 'checkbox' do |ba|
|
|
@@ -87,7 +97,7 @@ SimpleForm.setup do |config|
|
|
|
87
97
|
|
|
88
98
|
config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
89
99
|
b.use :html5
|
|
90
|
-
b.
|
|
100
|
+
b.optional :readonly
|
|
91
101
|
|
|
92
102
|
b.use :label, class: 'col-sm-3 control-label'
|
|
93
103
|
|
|
@@ -98,9 +108,29 @@ SimpleForm.setup do |config|
|
|
|
98
108
|
end
|
|
99
109
|
end
|
|
100
110
|
|
|
111
|
+
config.wrappers :inline_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
|
112
|
+
b.use :html5
|
|
113
|
+
b.use :placeholder
|
|
114
|
+
b.optional :maxlength
|
|
115
|
+
b.optional :pattern
|
|
116
|
+
b.optional :min_max
|
|
117
|
+
b.optional :readonly
|
|
118
|
+
b.use :label, class: 'sr-only'
|
|
119
|
+
|
|
120
|
+
b.use :input, class: 'form-control'
|
|
121
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
|
122
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
|
123
|
+
end
|
|
124
|
+
|
|
101
125
|
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
|
102
126
|
# Check the Bootstrap docs (http://getbootstrap.com)
|
|
103
127
|
# to learn about the different styles for forms and inputs,
|
|
104
128
|
# buttons and other elements.
|
|
105
129
|
config.default_wrapper = :vertical_form
|
|
130
|
+
config.wrapper_mappings = {
|
|
131
|
+
check_boxes: :vertical_radio_and_checkboxes,
|
|
132
|
+
radio_buttons: :vertical_radio_and_checkboxes,
|
|
133
|
+
file: :vertical_file_input,
|
|
134
|
+
boolean: :vertical_boolean,
|
|
135
|
+
}
|
|
106
136
|
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?
|
|
@@ -31,7 +31,7 @@ module SimpleForm
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
def label_text
|
|
34
|
+
def label_text(wrapper_options = nil)
|
|
35
35
|
label_text = options[:label_text] || SimpleForm.label_text
|
|
36
36
|
label_text.call(html_escape(raw_label_text), required_label_text, options[:label].present?).strip.html_safe
|
|
37
37
|
end
|
|
@@ -17,19 +17,19 @@ module SimpleForm
|
|
|
17
17
|
extend MapType
|
|
18
18
|
include SimpleForm::Inputs
|
|
19
19
|
|
|
20
|
-
map_type :text,
|
|
21
|
-
map_type :file,
|
|
22
|
-
map_type :string, :email, :search, :tel, :url, to: SimpleForm::Inputs::StringInput
|
|
23
|
-
map_type :password,
|
|
24
|
-
map_type :integer, :decimal, :float,
|
|
25
|
-
map_type :range,
|
|
26
|
-
map_type :check_boxes,
|
|
27
|
-
map_type :radio_buttons,
|
|
28
|
-
map_type :select,
|
|
29
|
-
map_type :grouped_select,
|
|
30
|
-
map_type :date, :time, :datetime,
|
|
31
|
-
map_type :country, :time_zone,
|
|
32
|
-
map_type :boolean,
|
|
20
|
+
map_type :text, to: SimpleForm::Inputs::TextInput
|
|
21
|
+
map_type :file, to: SimpleForm::Inputs::FileInput
|
|
22
|
+
map_type :string, :email, :search, :tel, :url, :uuid, to: SimpleForm::Inputs::StringInput
|
|
23
|
+
map_type :password, to: SimpleForm::Inputs::PasswordInput
|
|
24
|
+
map_type :integer, :decimal, :float, to: SimpleForm::Inputs::NumericInput
|
|
25
|
+
map_type :range, to: SimpleForm::Inputs::RangeInput
|
|
26
|
+
map_type :check_boxes, to: SimpleForm::Inputs::CollectionCheckBoxesInput
|
|
27
|
+
map_type :radio_buttons, to: SimpleForm::Inputs::CollectionRadioButtonsInput
|
|
28
|
+
map_type :select, to: SimpleForm::Inputs::CollectionSelectInput
|
|
29
|
+
map_type :grouped_select, to: SimpleForm::Inputs::GroupedCollectionSelectInput
|
|
30
|
+
map_type :date, :time, :datetime, to: SimpleForm::Inputs::DateTimeInput
|
|
31
|
+
map_type :country, :time_zone, to: SimpleForm::Inputs::PriorityInput
|
|
32
|
+
map_type :boolean, to: SimpleForm::Inputs::BooleanInput
|
|
33
33
|
|
|
34
34
|
def self.discovery_cache
|
|
35
35
|
@discovery_cache ||= {}
|
|
@@ -131,14 +131,15 @@ module SimpleForm
|
|
|
131
131
|
# name="user[name]" type="text" value="Carlos" />
|
|
132
132
|
#
|
|
133
133
|
def input_field(attribute_name, options = {})
|
|
134
|
+
components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)
|
|
135
|
+
|
|
134
136
|
options = options.dup
|
|
135
|
-
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *
|
|
137
|
+
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, *components)
|
|
136
138
|
options = @defaults.deep_dup.deep_merge(options) if @defaults
|
|
137
139
|
|
|
138
140
|
input = find_input(attribute_name, options)
|
|
139
141
|
wrapper = find_wrapper(input.input_type, options)
|
|
140
|
-
components =
|
|
141
|
-
components = components.map { |component| SimpleForm::Wrappers::Leaf.new(component) }
|
|
142
|
+
components = components.concat([:input]).map { |component| SimpleForm::Wrappers::Leaf.new(component) }
|
|
142
143
|
|
|
143
144
|
SimpleForm::Wrappers::Root.new(components, wrapper.options.merge(wrapper: false)).render input
|
|
144
145
|
end
|
|
@@ -542,7 +543,7 @@ module SimpleForm
|
|
|
542
543
|
end
|
|
543
544
|
|
|
544
545
|
def find_attribute_column(attribute_name)
|
|
545
|
-
if @object.respond_to?(:column_for_attribute)
|
|
546
|
+
if @object.respond_to?(:column_for_attribute) && @object.has_attribute?(attribute_name)
|
|
546
547
|
@object.column_for_attribute(attribute_name)
|
|
547
548
|
end
|
|
548
549
|
end
|
|
@@ -566,7 +567,9 @@ module SimpleForm
|
|
|
566
567
|
mapping_override(mapping) || mapping
|
|
567
568
|
else
|
|
568
569
|
camelized = "#{input_type.to_s.camelize}Input"
|
|
569
|
-
|
|
570
|
+
attempt_mapping_with_custom_namespace(camelized) ||
|
|
571
|
+
attempt_mapping(camelized, Object) ||
|
|
572
|
+
attempt_mapping(camelized, self.class) ||
|
|
570
573
|
raise("No input found for #{input_type}")
|
|
571
574
|
end
|
|
572
575
|
end
|
|
@@ -604,7 +607,9 @@ module SimpleForm
|
|
|
604
607
|
def mapping_override(klass)
|
|
605
608
|
name = klass.name
|
|
606
609
|
if name =~ /^SimpleForm::Inputs/
|
|
607
|
-
|
|
610
|
+
input_name = name.split("::").last
|
|
611
|
+
attempt_mapping_with_custom_namespace(input_name) ||
|
|
612
|
+
attempt_mapping(input_name, Object)
|
|
608
613
|
end
|
|
609
614
|
end
|
|
610
615
|
|
|
@@ -617,5 +622,15 @@ module SimpleForm
|
|
|
617
622
|
raise if e.message !~ /#{mapping}$/
|
|
618
623
|
end
|
|
619
624
|
end
|
|
625
|
+
|
|
626
|
+
def attempt_mapping_with_custom_namespace(input_name)
|
|
627
|
+
SimpleForm.custom_inputs_namespaces.each do |namespace|
|
|
628
|
+
if (mapping = attempt_mapping(input_name, namespace.constantize))
|
|
629
|
+
return mapping
|
|
630
|
+
end
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
nil
|
|
634
|
+
end
|
|
620
635
|
end
|
|
621
636
|
end
|