simple_form 2.0.0 → 2.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.
- data/CHANGELOG.md +34 -231
- data/MIT-LICENSE +1 -1
- data/README.md +221 -159
- data/lib/generators/simple_form/install_generator.rb +14 -5
- data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +8 -42
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +26 -0
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -5
- data/lib/simple_form/action_view_extensions/builder.rb +46 -30
- data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
- data/lib/simple_form/action_view_extensions/form_helper.rb +7 -9
- data/lib/simple_form/components/hints.rb +3 -2
- data/lib/simple_form/components/label_input.rb +1 -1
- data/lib/simple_form/components/labels.rb +1 -1
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +2 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +12 -10
- data/lib/simple_form/error_notification.rb +1 -1
- data/lib/simple_form/form_builder.rb +18 -8
- data/lib/simple_form/form_builder.rb.orig +486 -0
- data/lib/simple_form/helpers/validators.rb +2 -2
- data/lib/simple_form/inputs/base.rb +33 -8
- data/lib/simple_form/inputs/boolean_input.rb +19 -5
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -6
- data/lib/simple_form/inputs/date_time_input.rb +0 -4
- data/lib/simple_form/inputs.rb +19 -17
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/version.rb.orig +7 -0
- data/lib/simple_form/wrappers/many.rb +5 -1
- data/lib/simple_form/wrappers/root.rb +4 -2
- data/lib/simple_form/wrappers/single.rb +6 -0
- data/lib/simple_form.rb +17 -8
- data/test/action_view_extensions/builder_test.rb +145 -66
- data/test/action_view_extensions/form_helper_test.rb +59 -20
- data/test/components/label_test.rb +34 -17
- data/test/form_builder/association_test.rb +19 -10
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/general_test.rb +74 -12
- data/test/form_builder/hint_test.rb +15 -0
- data/test/form_builder/input_field_test.rb +45 -0
- data/test/form_builder/label_test.rb +6 -0
- data/test/form_builder/wrapper_test.rb +58 -4
- data/test/generators/simple_form_generator_test.rb +11 -1
- data/test/inputs/boolean_input_test.rb +39 -0
- data/test/inputs/datetime_input_test.rb +2 -2
- data/test/inputs/disabled_test.rb +51 -11
- data/test/inputs/discovery_test.rb +9 -1
- data/test/inputs/general_test.rb +58 -11
- data/test/inputs/grouped_collection_select_input_test.rb +15 -0
- data/test/inputs/numeric_input_test.rb +6 -0
- data/test/inputs/readonly_test.rb +51 -11
- data/test/inputs/string_input_test.rb +6 -0
- data/test/support/discovery_inputs.rb +6 -0
- data/test/support/misc_helpers.rb +41 -1
- data/test/support/models.rb +8 -4
- data/test/test_helper.rb +8 -6
- metadata +26 -13
- data/test/support/mock_response.rb +0 -14
|
@@ -5,7 +5,7 @@ module SimpleForm
|
|
|
5
5
|
if nested_boolean_style?
|
|
6
6
|
build_hidden_field_for_checkbox +
|
|
7
7
|
template.label_tag(nil, :class => "checkbox") {
|
|
8
|
-
build_check_box_without_hidden_field
|
|
8
|
+
build_check_box_without_hidden_field + inline_label
|
|
9
9
|
}
|
|
10
10
|
else
|
|
11
11
|
build_check_box
|
|
@@ -34,8 +34,8 @@ module SimpleForm
|
|
|
34
34
|
# reuse the method for nested boolean style, but with no unchecked value,
|
|
35
35
|
# which won't generate the hidden checkbox. This is the default functionality
|
|
36
36
|
# in Rails > 3.2.1, and is backported in SimpleForm AV helpers.
|
|
37
|
-
def build_check_box(unchecked_value=
|
|
38
|
-
@builder.check_box(attribute_name, input_html_options,
|
|
37
|
+
def build_check_box(unchecked_value = unchecked_value)
|
|
38
|
+
@builder.check_box(attribute_name, input_html_options, checked_value, unchecked_value)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Build a checkbox without generating the hidden field. See
|
|
@@ -49,8 +49,14 @@ module SimpleForm
|
|
|
49
49
|
# we need the hidden field to be *outside* the label (otherwise it
|
|
50
50
|
# generates invalid html - html5 only).
|
|
51
51
|
def build_hidden_field_for_checkbox
|
|
52
|
-
@builder.hidden_field(attribute_name, :value =>
|
|
53
|
-
:disabled => input_html_options[:disabled]
|
|
52
|
+
@builder.hidden_field(attribute_name, :value => unchecked_value, :id => nil,
|
|
53
|
+
:disabled => input_html_options[:disabled],
|
|
54
|
+
:name => input_html_options[:name])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def inline_label
|
|
58
|
+
inline_option = options[:inline_label]
|
|
59
|
+
inline_option == true ? label_text : inline_option
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
# Booleans are not required by default because in most of the cases
|
|
@@ -59,6 +65,14 @@ module SimpleForm
|
|
|
59
65
|
def required_by_default?
|
|
60
66
|
false
|
|
61
67
|
end
|
|
68
|
+
|
|
69
|
+
def checked_value
|
|
70
|
+
options.fetch(:checked_value, '1')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def unchecked_value
|
|
74
|
+
options.fetch(:unchecked_value, '0')
|
|
75
|
+
end
|
|
62
76
|
end
|
|
63
77
|
end
|
|
64
78
|
end
|
|
@@ -20,16 +20,12 @@ module SimpleForm
|
|
|
20
20
|
protected
|
|
21
21
|
|
|
22
22
|
def apply_default_collection_options!(options)
|
|
23
|
-
|
|
24
|
-
options[:item_wrapper_tag] = SimpleForm.item_wrapper_tag
|
|
25
|
-
end
|
|
23
|
+
options[:item_wrapper_tag] ||= options.fetch(:item_wrapper_tag, SimpleForm.item_wrapper_tag)
|
|
26
24
|
options[:item_wrapper_class] = [
|
|
27
25
|
item_wrapper_class, options[:item_wrapper_class], SimpleForm.item_wrapper_class
|
|
28
26
|
].compact.presence
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
options[:collection_wrapper_tag] = SimpleForm.collection_wrapper_tag
|
|
32
|
-
end
|
|
28
|
+
options[:collection_wrapper_tag] ||= options.fetch(:collection_wrapper_tag, SimpleForm.collection_wrapper_tag)
|
|
33
29
|
options[:collection_wrapper_class] = [
|
|
34
30
|
options[:collection_wrapper_class], SimpleForm.collection_wrapper_class
|
|
35
31
|
].compact.presence
|
data/lib/simple_form/inputs.rb
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
module SimpleForm
|
|
2
2
|
module Inputs
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
autoload :
|
|
6
|
-
autoload :
|
|
7
|
-
autoload :
|
|
8
|
-
autoload :
|
|
9
|
-
autoload :
|
|
10
|
-
autoload :
|
|
11
|
-
autoload :
|
|
12
|
-
autoload :
|
|
13
|
-
autoload :
|
|
14
|
-
autoload :
|
|
15
|
-
autoload :
|
|
16
|
-
autoload :
|
|
17
|
-
autoload :
|
|
18
|
-
autoload :
|
|
19
|
-
autoload :
|
|
3
|
+
extend ActiveSupport::Autoload
|
|
4
|
+
|
|
5
|
+
autoload :Base
|
|
6
|
+
autoload :BlockInput
|
|
7
|
+
autoload :BooleanInput
|
|
8
|
+
autoload :CollectionCheckBoxesInput
|
|
9
|
+
autoload :CollectionInput
|
|
10
|
+
autoload :CollectionRadioButtonsInput
|
|
11
|
+
autoload :CollectionSelectInput
|
|
12
|
+
autoload :DateTimeInput
|
|
13
|
+
autoload :FileInput
|
|
14
|
+
autoload :GroupedCollectionSelectInput
|
|
15
|
+
autoload :HiddenInput
|
|
16
|
+
autoload :NumericInput
|
|
17
|
+
autoload :PasswordInput
|
|
18
|
+
autoload :PriorityInput
|
|
19
|
+
autoload :RangeInput
|
|
20
|
+
autoload :StringInput
|
|
21
|
+
autoload :TextInput
|
|
20
22
|
end
|
|
21
23
|
end
|
data/lib/simple_form/version.rb
CHANGED
|
@@ -56,11 +56,15 @@ module SimpleForm
|
|
|
56
56
|
return content unless tag
|
|
57
57
|
|
|
58
58
|
klass = html_classes(input, options)
|
|
59
|
-
opts = options
|
|
59
|
+
opts = html_options(options)
|
|
60
60
|
opts[:class] = (klass << opts[:class]).join(' ').strip unless klass.empty?
|
|
61
61
|
input.template.content_tag(tag, content, opts)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
def html_options(options)
|
|
65
|
+
options[:"#{namespace}_html"] || {}
|
|
66
|
+
end
|
|
67
|
+
|
|
64
68
|
def html_classes(input, options)
|
|
65
69
|
@defaults[:class].dup
|
|
66
70
|
end
|
|
@@ -24,10 +24,12 @@ module SimpleForm
|
|
|
24
24
|
|
|
25
25
|
def html_classes(input, options)
|
|
26
26
|
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
|
27
|
-
css += SimpleForm.additional_classes_for(:wrapper)
|
|
27
|
+
css += SimpleForm.additional_classes_for(:wrapper) do
|
|
28
|
+
input.additional_classes + [input.input_class]
|
|
29
|
+
end
|
|
28
30
|
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
|
29
31
|
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
|
30
|
-
css
|
|
32
|
+
css.compact
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
end
|
data/lib/simple_form.rb
CHANGED
|
@@ -6,14 +6,17 @@ require 'active_support/core_ext/hash/except'
|
|
|
6
6
|
require 'active_support/core_ext/hash/reverse_merge'
|
|
7
7
|
|
|
8
8
|
module SimpleForm
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
autoload :
|
|
12
|
-
autoload :
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
extend ActiveSupport::Autoload
|
|
10
|
+
|
|
11
|
+
autoload :Helpers
|
|
12
|
+
autoload :Wrappers
|
|
13
|
+
|
|
14
|
+
eager_autoload do
|
|
15
|
+
autoload :Components
|
|
16
|
+
autoload :ErrorNotification
|
|
17
|
+
autoload :FormBuilder
|
|
18
|
+
autoload :Inputs
|
|
19
|
+
end
|
|
17
20
|
|
|
18
21
|
## CONFIGURATION OPTIONS
|
|
19
22
|
|
|
@@ -95,6 +98,12 @@ module SimpleForm
|
|
|
95
98
|
mattr_accessor :input_mappings
|
|
96
99
|
@@input_mappings = nil
|
|
97
100
|
|
|
101
|
+
# Custom wrappers for input types. This should be a hash containing an input
|
|
102
|
+
# type as key and the wrapper that will be used for all inputs with specified type.
|
|
103
|
+
# e.g { :string => :string_wrapper, :boolean => :boolean_wrapper }
|
|
104
|
+
mattr_accessor :wrapper_mappings
|
|
105
|
+
@@wrapper_mappings = nil
|
|
106
|
+
|
|
98
107
|
# Default priority for time_zone inputs.
|
|
99
108
|
mattr_accessor :time_zone_priority
|
|
100
109
|
@@time_zone_priority = nil
|