simple_form 2.0.0 → 2.0.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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- data/CHANGELOG.md +10 -0
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +3 -0
- data/lib/simple_form/action_view_extensions/builder.rb +7 -8
- data/lib/simple_form/form_builder.rb +1 -1
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -6
- data/lib/simple_form/version.rb +1 -1
- data/test/action_view_extensions/builder_test.rb +21 -0
- data/test/form_builder/label_test.rb +6 -0
- metadata +6 -12
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 2.0.1
|
2
|
+
|
3
|
+
### bug fix
|
4
|
+
* Sanitaze html attributes to `label` method. ([@nashby](https://github.com/nashby)).
|
5
|
+
Closes [#472](https://github.com/plataformatec/simple_form/issues/472)
|
6
|
+
* Make `collection_check_boxes` and `collection_radio_buttons` work with local variables.
|
7
|
+
Closes [#474](https://github.com/plataformatec/simple_form/issues/474)
|
8
|
+
* Use `html5` component by default in the bootstrap generator. ([@isc](https://github.com/isc)).
|
9
|
+
Closes [#471](https://github.com/plataformatec/simple_form/issues/471)
|
10
|
+
|
1
11
|
## 2.0.0
|
2
12
|
|
3
13
|
### enhancements
|
@@ -46,6 +46,7 @@ SimpleForm.setup do |config|
|
|
46
46
|
end
|
47
47
|
<% if options.bootstrap? %>
|
48
48
|
config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
|
49
|
+
b.use :html5
|
49
50
|
b.use :placeholder
|
50
51
|
b.use :label
|
51
52
|
b.wrapper :tag => 'div', :class => 'controls' do |ba|
|
@@ -56,6 +57,7 @@ SimpleForm.setup do |config|
|
|
56
57
|
end
|
57
58
|
|
58
59
|
config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
60
|
+
b.use :html5
|
59
61
|
b.use :placeholder
|
60
62
|
b.use :label
|
61
63
|
b.wrapper :tag => 'div', :class => 'controls' do |input|
|
@@ -68,6 +70,7 @@ SimpleForm.setup do |config|
|
|
68
70
|
end
|
69
71
|
|
70
72
|
config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
73
|
+
b.use :html5
|
71
74
|
b.use :placeholder
|
72
75
|
b.use :label
|
73
76
|
b.wrapper :tag => 'div', :class => 'controls' do |input|
|
@@ -5,10 +5,9 @@ module SimpleForm
|
|
5
5
|
class BuilderBase #:nodoc:
|
6
6
|
attr_reader :object, :text, :value
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
10
|
-
@
|
11
|
-
@object_name = object_name
|
8
|
+
def initialize(form_builder, method_name, object, sanitized_attribute_name, text,
|
9
|
+
value, input_html_options)
|
10
|
+
@form_builder = form_builder
|
12
11
|
@method_name = method_name
|
13
12
|
@object = object
|
14
13
|
@sanitized_attribute_name = sanitized_attribute_name
|
@@ -18,7 +17,7 @@ module SimpleForm
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def label(label_html_options={}, &block)
|
21
|
-
@
|
20
|
+
@form_builder.label(@sanitized_attribute_name, @text, label_html_options, &block)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -26,7 +25,7 @@ module SimpleForm
|
|
26
25
|
class RadioButtonBuilder < BuilderBase #:nodoc:
|
27
26
|
def radio_button(extra_html_options={})
|
28
27
|
html_options = extra_html_options.merge(@input_html_options)
|
29
|
-
@
|
28
|
+
@form_builder.radio_button(@method_name, @value, html_options)
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -34,7 +33,7 @@ module SimpleForm
|
|
34
33
|
class CheckBoxBuilder < BuilderBase #:nodoc:
|
35
34
|
def check_box(extra_html_options={})
|
36
35
|
html_options = extra_html_options.merge(@input_html_options)
|
37
|
-
@
|
36
|
+
@form_builder.check_box(@method_name, html_options, @value, nil)
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
@@ -207,7 +206,7 @@ module SimpleForm
|
|
207
206
|
private
|
208
207
|
|
209
208
|
def instantiate_builder(builder_class, attribute, item, value, text, html_options)
|
210
|
-
builder_class.new(
|
209
|
+
builder_class.new(self, attribute, item,
|
211
210
|
sanitize_attribute_name(attribute, value), text, value, html_options)
|
212
211
|
end
|
213
212
|
|
@@ -303,7 +303,7 @@ module SimpleForm
|
|
303
303
|
return super if args.first.is_a?(String) || block_given?
|
304
304
|
|
305
305
|
options = args.extract_options!.dup
|
306
|
-
options[:label_html] = options.except(:label, :required)
|
306
|
+
options[:label_html] = options.except(:label, :required, :as)
|
307
307
|
|
308
308
|
column = find_attribute_column(attribute_name)
|
309
309
|
input_type = default_input_type(attribute_name, column, options)
|
@@ -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/version.rb
CHANGED
@@ -48,6 +48,15 @@ class BuilderTest < ActionView::TestCase
|
|
48
48
|
assert_select 'label.collection_radio_buttons[for=user_name_199]', '$1.99'
|
49
49
|
end
|
50
50
|
|
51
|
+
test 'collection radio checks the correct value to local variables' do
|
52
|
+
user = User.new
|
53
|
+
user.active = false
|
54
|
+
with_collection_radio_buttons user, :active, [true, false], :to_s, :to_s
|
55
|
+
|
56
|
+
assert_select 'form input[type=radio][value=true]'
|
57
|
+
assert_select 'form input[type=radio][value=false][checked=checked]'
|
58
|
+
end
|
59
|
+
|
51
60
|
test 'collection radio accepts checked item' do
|
52
61
|
with_collection_radio_buttons @user, :active, [[1, true], [0, false]], :last, :first, :checked => true
|
53
62
|
|
@@ -276,6 +285,18 @@ class BuilderTest < ActionView::TestCase
|
|
276
285
|
assert_select 'label.collection_check_boxes[for=user_name_199]', '$1.99'
|
277
286
|
end
|
278
287
|
|
288
|
+
test 'collection check box checks the correct value to local variables' do
|
289
|
+
user = User.new
|
290
|
+
user.tag_ids = [1, 3]
|
291
|
+
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
292
|
+
with_collection_check_boxes user, :tag_ids, collection, :first, :last
|
293
|
+
|
294
|
+
assert_select 'form input[type=checkbox][value=1][checked=checked]'
|
295
|
+
assert_select 'form input[type=checkbox][value=3][checked=checked]'
|
296
|
+
assert_no_select 'form input[type=checkbox][value=2][checked=checked]'
|
297
|
+
end
|
298
|
+
|
299
|
+
|
279
300
|
test 'collection check box accepts selected values as :checked option' do
|
280
301
|
collection = (1..3).map{|i| [i, "Tag #{i}"] }
|
281
302
|
with_collection_check_boxes @user, :tag_ids, collection, :first, :last, :checked => [1, 3]
|
@@ -13,6 +13,12 @@ class LabelTest < ActionView::TestCase
|
|
13
13
|
assert_select 'label.string[for=user_name]', /Name/
|
14
14
|
end
|
15
15
|
|
16
|
+
test 'builder should generate a label for the boolean attrbiute' do
|
17
|
+
with_label_for @user, :name, :as => :boolean
|
18
|
+
assert_select 'label.boolean[for=user_name]', /Name/
|
19
|
+
assert_no_select 'label[as=boolean]'
|
20
|
+
end
|
21
|
+
|
16
22
|
test 'builder should generate a label componet tag with a clean HTML' do
|
17
23
|
with_label_for @user, :name
|
18
24
|
assert_no_select 'label.string[label_html]'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-02-
|
14
|
+
date: 2012-02-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activemodel
|
18
|
-
requirement: &
|
18
|
+
requirement: &70290445717740 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70290445717740
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
|
-
requirement: &
|
29
|
+
requirement: &70290445716540 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: '3.0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70290445716540
|
38
38
|
description: Forms made easy!
|
39
39
|
email: contact@plataformatec.com.br
|
40
40
|
executables: []
|
@@ -150,18 +150,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- - ! '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
segments:
|
154
|
-
- 0
|
155
|
-
hash: 284620577294605378
|
156
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
154
|
none: false
|
158
155
|
requirements:
|
159
156
|
- - ! '>='
|
160
157
|
- !ruby/object:Gem::Version
|
161
158
|
version: '0'
|
162
|
-
segments:
|
163
|
-
- 0
|
164
|
-
hash: 284620577294605378
|
165
159
|
requirements: []
|
166
160
|
rubyforge_project: simple_form
|
167
161
|
rubygems_version: 1.8.11
|