simple_form 3.1.0.rc2 → 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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +27 -10
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +3 -2
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +8 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +85 -4
- data/lib/simple_form.rb +13 -2
- 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/form_builder.rb +5 -4
- data/lib/simple_form/inputs/boolean_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +2 -4
- data/lib/simple_form/tags.rb +2 -4
- data/lib/simple_form/version.rb +1 -1
- 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 +70 -11
- data/test/form_builder/general_test.rb +24 -4
- data/test/form_builder/hint_test.rb +3 -3
- data/test/form_builder/input_field_test.rb +43 -3
- data/test/form_builder/label_test.rb +1 -1
- data/test/form_builder/wrapper_test.rb +18 -3
- 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 +1 -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/string_input_test.rb +10 -10
- data/test/inputs/text_input_test.rb +3 -3
- data/test/support/misc_helpers.rb +6 -0
- data/test/support/models.rb +11 -1
- 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,7 @@
|
|
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)
|
4
5
|
* Add mapping to `uuid` columns.
|
5
6
|
* Add custom namespaces for custom inputs feature. [@vala](https://github.com/vala)
|
6
7
|
* Add `:unless_blank` option to the wrapper API. [@IanVaughan](https://github.com/IanVaughan)
|
@@ -27,8 +28,11 @@
|
|
27
28
|
* Add I18n support to `:include_blank` and `:prompt` when `:translate` is used as value. [@haines](https://github.com/plataformatec/simple_form/pull/616)
|
28
29
|
* Add support to define custom error messages for the attributes.
|
29
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)
|
30
32
|
|
31
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.
|
32
36
|
* Collection input that uses automatic collection translation properly sets checked values.
|
33
37
|
Closes [#971](https://github.com/plataformatec/simple_form/issues/971) [@nashby](https://github.com/nashby)
|
34
38
|
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
@@ -37,5 +41,9 @@
|
|
37
41
|
## deprecation
|
38
42
|
* Methods on custom inputs now accept a required argument with the wrapper options.
|
39
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.
|
40
48
|
|
41
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
|
|
@@ -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
|
@@ -547,7 +553,9 @@ that extends the string one, you just need to add this file:
|
|
547
553
|
# app/inputs/currency_input.rb
|
548
554
|
class CurrencyInput < SimpleForm::Inputs::Base
|
549
555
|
def input(wrapper_options)
|
550
|
-
|
556
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
557
|
+
|
558
|
+
"$ #{@builder.text_field(attribute_name, merged_input_options)}".html_safe
|
551
559
|
end
|
552
560
|
end
|
553
561
|
```
|
@@ -977,11 +985,20 @@ You can also add `novalidate` to a specific form by setting the option on the fo
|
|
977
985
|
<%= simple_form_for(resource, html: { novalidate: true }) do |form| %>
|
978
986
|
```
|
979
987
|
|
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.
|
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
|
+
```
|
985
1002
|
|
986
1003
|
## Information
|
987
1004
|
|
@@ -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
|
@@ -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]
|
@@ -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
|
@@ -126,4 +127,10 @@ SimpleForm.setup do |config|
|
|
126
127
|
# to learn about the different styles for forms and inputs,
|
127
128
|
# buttons and other elements.
|
128
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
|
+
}
|
129
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
|
data/lib/simple_form.rb
CHANGED
@@ -96,10 +96,16 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
96
96
|
mattr_accessor :boolean_style
|
97
97
|
@@boolean_style = :inline
|
98
98
|
|
99
|
-
# You can define the class to be used on all forms. Default is
|
100
|
-
|
99
|
+
# DEPRECATED: You can define the class to be used on all forms. Default is
|
100
|
+
# simple_form.
|
101
|
+
mattr_reader :form_class
|
101
102
|
@@form_class = :simple_form
|
102
103
|
|
104
|
+
# You can define the default class to be used on all forms. Can be overriden
|
105
|
+
# with `html: { :class }`. Defaults to none.
|
106
|
+
mattr_accessor :default_form_class
|
107
|
+
@@default_form_class = nil
|
108
|
+
|
103
109
|
# You can define which elements should obtain additional classes.
|
104
110
|
mattr_accessor :generate_additional_classes_for
|
105
111
|
@@generate_additional_classes_for = [:wrapper, :label, :input]
|
@@ -249,6 +255,11 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|
249
255
|
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
|
250
256
|
end
|
251
257
|
|
258
|
+
def self.form_class=(value)
|
259
|
+
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.form_class= is deprecated and will be removed in 4.x. Use SimpleForm.default_form_class= instead", caller
|
260
|
+
@@form_class = value
|
261
|
+
end
|
262
|
+
|
252
263
|
# Default way to setup Simple Form. Run rails generate simple_form:install
|
253
264
|
# to create a fresh initializer with all configuration values.
|
254
265
|
def self.setup
|
@@ -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?
|
@@ -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
|
@@ -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
|
data/lib/simple_form/tags.rb
CHANGED
@@ -16,11 +16,9 @@ module SimpleForm
|
|
16
16
|
rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
|
17
17
|
|
18
18
|
if @options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
|
19
|
-
label_options =
|
20
|
-
add_default_name_and_id_for_value(value, label_options)
|
21
|
-
label_options['for'] = label_options.delete('id')
|
19
|
+
label_options = default_html_options.slice(:index, :namespace)
|
22
20
|
label_options['class'] = @options[:item_label_class]
|
23
|
-
rendered_item =
|
21
|
+
rendered_item = @template_object.label(@object_name, sanitize_attribute_name(value), rendered_item, label_options)
|
24
22
|
end
|
25
23
|
|
26
24
|
item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
|
data/lib/simple_form/version.rb
CHANGED
@@ -263,15 +263,15 @@ class BuilderTest < ActionView::TestCase
|
|
263
263
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
264
264
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
265
265
|
|
266
|
-
assert_select 'form input#user_tag_ids_1[type=checkbox][value=1]'
|
267
|
-
assert_select 'form input#user_tag_ids_2[type=checkbox][value=2]'
|
266
|
+
assert_select 'form input#user_tag_ids_1[type=checkbox][value="1"]'
|
267
|
+
assert_select 'form input#user_tag_ids_2[type=checkbox][value="2"]'
|
268
268
|
end
|
269
269
|
|
270
270
|
test "collection check box generates only one hidden field for the entire collection, to ensure something will be sent back to the server when posting an empty collection" do
|
271
271
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
272
272
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
273
273
|
|
274
|
-
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", count: 1
|
274
|
+
assert_select "form input[type=hidden][name='user[tag_ids][]'][value='']", count: 1
|
275
275
|
end
|
276
276
|
|
277
277
|
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
@@ -301,36 +301,36 @@ class BuilderTest < ActionView::TestCase
|
|
301
301
|
|
302
302
|
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
303
303
|
|
304
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
305
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
306
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
304
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
305
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
306
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
307
307
|
end
|
308
308
|
|
309
309
|
test "collection check box accepts selected values as :checked option" do
|
310
310
|
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
311
311
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
312
312
|
|
313
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
314
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
315
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
313
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
314
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
315
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
316
316
|
end
|
317
317
|
|
318
318
|
test "collection check boxes accepts selected string values as :checked option" do
|
319
319
|
collection = (1..3).map { |i| [i, "Category #{i}"] }
|
320
320
|
with_collection_check_boxes :user, :category_ids, collection, :first, :last, checked: ['1', '3']
|
321
321
|
|
322
|
-
assert_select 'input[type=checkbox][value=1][checked=checked]'
|
323
|
-
assert_select 'input[type=checkbox][value=3][checked=checked]'
|
324
|
-
assert_no_select 'input[type=checkbox][value=2][checked=checked]'
|
322
|
+
assert_select 'input[type=checkbox][value="1"][checked=checked]'
|
323
|
+
assert_select 'input[type=checkbox][value="3"][checked=checked]'
|
324
|
+
assert_no_select 'input[type=checkbox][value="2"][checked=checked]'
|
325
325
|
end
|
326
326
|
|
327
327
|
test "collection check box accepts a single checked value" do
|
328
328
|
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
329
329
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: 3
|
330
330
|
|
331
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
332
|
-
assert_no_select 'form input[type=checkbox][value=1][checked=checked]'
|
333
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
331
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
332
|
+
assert_no_select 'form input[type=checkbox][value="1"][checked=checked]'
|
333
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
334
334
|
end
|
335
335
|
|
336
336
|
test "collection check box accepts selected values as :checked option and override the model values" do
|
@@ -338,44 +338,44 @@ class BuilderTest < ActionView::TestCase
|
|
338
338
|
@user.tag_ids = [2]
|
339
339
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, checked: [1, 3]
|
340
340
|
|
341
|
-
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
342
|
-
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
343
|
-
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
341
|
+
assert_select 'form input[type=checkbox][value="1"][checked=checked]'
|
342
|
+
assert_select 'form input[type=checkbox][value="3"][checked=checked]'
|
343
|
+
assert_no_select 'form input[type=checkbox][value="2"][checked=checked]'
|
344
344
|
end
|
345
345
|
|
346
346
|
test "collection check box accepts multiple disabled items" do
|
347
347
|
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
348
348
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: [1, 3]
|
349
349
|
|
350
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
351
|
-
assert_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
352
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
350
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
351
|
+
assert_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
352
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
353
353
|
end
|
354
354
|
|
355
355
|
test "collection check box accepts single disable item" do
|
356
356
|
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
357
357
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: 1
|
358
358
|
|
359
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
360
|
-
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
361
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
359
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
360
|
+
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
361
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
362
362
|
end
|
363
363
|
|
364
364
|
test "collection check box accepts a proc to disabled items" do
|
365
365
|
collection = (1..3).map { |i| [i, "Tag #{i}"] }
|
366
366
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, disabled: proc { |i| i.first == 1 }
|
367
367
|
|
368
|
-
assert_select 'form input[type=checkbox][value=1][disabled=disabled]'
|
369
|
-
assert_no_select 'form input[type=checkbox][value=3][disabled=disabled]'
|
370
|
-
assert_no_select 'form input[type=checkbox][value=2][disabled=disabled]'
|
368
|
+
assert_select 'form input[type=checkbox][value="1"][disabled=disabled]'
|
369
|
+
assert_no_select 'form input[type=checkbox][value="3"][disabled=disabled]'
|
370
|
+
assert_no_select 'form input[type=checkbox][value="2"][disabled=disabled]'
|
371
371
|
end
|
372
372
|
|
373
373
|
test "collection check box accepts html options" do
|
374
374
|
collection = [[1, 'Tag 1'], [2, 'Tag 2']]
|
375
375
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, {}, class: 'check'
|
376
376
|
|
377
|
-
assert_select 'form input.check[type=checkbox][value=1]'
|
378
|
-
assert_select 'form input.check[type=checkbox][value=2]'
|
377
|
+
assert_select 'form input.check[type=checkbox][value="1"]'
|
378
|
+
assert_select 'form input.check[type=checkbox][value="2"]'
|
379
379
|
end
|
380
380
|
|
381
381
|
test "collection check box with fields for" do
|
@@ -386,8 +386,8 @@ class BuilderTest < ActionView::TestCase
|
|
386
386
|
end
|
387
387
|
end
|
388
388
|
|
389
|
-
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value=1]'
|
390
|
-
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value=2]'
|
389
|
+
assert_select 'form input#user_post_tag_ids_1[type=checkbox][value="1"]'
|
390
|
+
assert_select 'form input#user_post_tag_ids_2[type=checkbox][value="2"]'
|
391
391
|
|
392
392
|
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_1]', 'Tag 1'
|
393
393
|
assert_select 'form label.collection_check_boxes[for=user_post_tag_ids_2]', 'Tag 2'
|