simple_form 2.1.2 → 2.1.3
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 +11 -1
- data/README.md +46 -38
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +1 -1
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +2 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -1
- data/lib/simple_form/form_builder.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +2 -1
- data/lib/simple_form/inputs/collection_input.rb +1 -1
- data/lib/simple_form/version.rb +1 -1
- data/test/action_view_extensions/builder_test.rb +7 -0
- data/test/form_builder/general_test.rb +20 -0
- data/test/inputs/boolean_input_test.rb +12 -0
- data/test/inputs/collection_select_input_test.rb +6 -0
- data/test/support/models.rb +3 -0
- data/test/test_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0846cac8facbc990fc17731962d98598a2e40ee
|
4
|
+
data.tar.gz: 4e1b4b5645eb07f7273b89b4a50007a6cc72fb82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aeca7d6cf3e6ea92299c4a55f7483e5f9ef3c49fc9497840cb11109eb57872cebc98b71c49669b5334cd8409dae300e40409fae39c0d9f2634060fdf65fb95c
|
7
|
+
data.tar.gz: 7c9fe5310c7403486fbbeeeb2f4633fb9e6987b6c22e663d727e6eacd41f357252a705ac31e5e91cf03575cc053b153f7fa1ff3f31b0545b9ce82ffb34510582
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 2.1.3
|
2
|
+
|
3
|
+
### bug fix
|
4
|
+
* Fix method reflection for Ruby 2.1+. [@badosu](https://github.com/badosu)
|
5
|
+
* Collection input generates `required` attribute if it has `prompt` option. [@nashby](https://github.com/nashby)
|
6
|
+
* Use the given name in `input_html` for the hidden field in `collection_check_boxes` [@angelic](https://github.com/angelic)
|
7
|
+
* Add "checkbox" class to the label of boolean input when there is no `:label`
|
8
|
+
in `generate_additional_classes_for` config option [@nashby](https://github.com/nashby)
|
9
|
+
* Support models with digits in their names [@webgago](https://github.com/webgago)
|
10
|
+
|
1
11
|
## 2.1.2
|
2
12
|
|
3
13
|
### bug fix
|
@@ -13,7 +23,7 @@
|
|
13
23
|
### enhancements
|
14
24
|
* `input_field` supports components that don't generate tags
|
15
25
|
as `:min_max`, `:maxlength`, `:placeholder`, `:pattern`, `:readonly`.
|
16
|
-
Closes[#362](https://github.com/plataformatec/simple_form/issues/632).
|
26
|
+
Closes [#362](https://github.com/plataformatec/simple_form/issues/632).
|
17
27
|
([@nashby](https://github.com/nashby))
|
18
28
|
* support for Rails eager loading.
|
19
29
|
Closes [#478](https://github.com/plataformatec/simple_form/issues/478).
|
data/README.md
CHANGED
@@ -35,23 +35,23 @@ Also, if you want to use the country select, you will need the
|
|
35
35
|
gem 'country_select'
|
36
36
|
```
|
37
37
|
|
38
|
-
###
|
38
|
+
### Bootstrap
|
39
39
|
|
40
|
-
**
|
40
|
+
**Simple Form** can be easily integrated to the [Bootstrap](http://getbootstrap.com/2.3.2/) 2.3.
|
41
41
|
To do that you have to use the `bootstrap` option in the install generator, like this:
|
42
42
|
|
43
43
|
```console
|
44
44
|
rails generate simple_form:install --bootstrap
|
45
45
|
```
|
46
46
|
|
47
|
-
You have to be sure that you added a copy of the [
|
47
|
+
You have to be sure that you added a copy of the [Bootstrap](http://getbootstrap.com/2.3.2/)
|
48
48
|
assets on your application.
|
49
49
|
|
50
50
|
For more information see the generator output, our
|
51
51
|
[example application code](https://github.com/rafaelfranca/simple_form-bootstrap) and
|
52
52
|
[the live example app](http://simple-form-bootstrap.plataformatec.com.br/).
|
53
53
|
|
54
|
-
**NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0
|
54
|
+
**NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 up to 2.3.
|
55
55
|
|
56
56
|
### Zurb Foundation 3
|
57
57
|
|
@@ -163,6 +163,13 @@ And of course, the `required` property of any input can be overwritten as needed
|
|
163
163
|
<% end %>
|
164
164
|
```
|
165
165
|
|
166
|
+
By default, SimpleForm will look at the column type in the database and use an
|
167
|
+
appropriate input for the column. For example, a column created with type
|
168
|
+
`:text` in the database will use a `textarea` input by default. See the section
|
169
|
+
[Available input types and defaults for each column
|
170
|
+
type](https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type)
|
171
|
+
for a complete list of defaults.
|
172
|
+
|
166
173
|
**SimpleForm** also lets you overwrite the default input type it creates:
|
167
174
|
|
168
175
|
```erb
|
@@ -176,7 +183,7 @@ And of course, the `required` property of any input can be overwritten as needed
|
|
176
183
|
```
|
177
184
|
|
178
185
|
So instead of a checkbox for the *accepts* attribute, you'll have a pair of radio buttons with yes/no
|
179
|
-
labels and a
|
186
|
+
labels and a textarea instead of a text field for the description. You can also render boolean
|
180
187
|
attributes using `:as => :select` to show a dropdown.
|
181
188
|
|
182
189
|
It is also possible to give the `:disabled` option to **SimpleForm**, and it'll automatically mark
|
@@ -289,7 +296,7 @@ f.input :shipping_country, :priority => [ "Brazil" ], :collection => [ "Australi
|
|
289
296
|
|
290
297
|
### Associations
|
291
298
|
|
292
|
-
To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or
|
299
|
+
To deal with associations, **SimpleForm** can generate select inputs, a series of radios buttons or checkboxes.
|
293
300
|
Lets see how it works: imagine you have a user model that belongs to a company and has_and_belongs_to_many
|
294
301
|
roles. The structure would be something like:
|
295
302
|
|
@@ -321,7 +328,7 @@ Now we have the user form:
|
|
321
328
|
|
322
329
|
Simple enough, right? This is going to render a `:select` input for choosing the `:company`, and another
|
323
330
|
`:select` input with `:multiple` option for the `:roles`. You can, of course, change it to use radio
|
324
|
-
buttons and
|
331
|
+
buttons and checkboxes as well:
|
325
332
|
|
326
333
|
```ruby
|
327
334
|
f.association :company, :as => :radio_buttons
|
@@ -408,7 +415,7 @@ end
|
|
408
415
|
|
409
416
|
#### Collection Check Boxes
|
410
417
|
|
411
|
-
Creates a collection of
|
418
|
+
Creates a collection of checkboxes with labels associated (same API as `collection_select`):
|
412
419
|
|
413
420
|
```ruby
|
414
421
|
form_for @user do |f|
|
@@ -433,36 +440,36 @@ form_for @user do |f|
|
|
433
440
|
end
|
434
441
|
```
|
435
442
|
|
436
|
-
##
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
443
|
+
## Available input types and defaults for each column type
|
444
|
+
|
445
|
+
The following table shows the html element you will get for each attribute
|
446
|
+
according to its database definition. These defaults can be changed by
|
447
|
+
specifying the helper method in the column `Mapping` as the `as:` option.
|
448
|
+
|
449
|
+
Mapping | Generated HTML Element | Database Column Type
|
450
|
+
--------------- |:-------------------------------------|:--------------------
|
451
|
+
`boolean` | `input[type=checkbox]` | `boolean`
|
452
|
+
`string` | `input[type=text]` | `string`
|
453
|
+
`email` | `input[type=email]` | `string` with `name =~ /email/`
|
454
|
+
`url` | `input[type=url]` | `string` with `name =~ /url/`
|
455
|
+
`tel` | `input[type=tel]` | `string` with `name =~ /phone/`
|
456
|
+
`password` | `input[type=password]` | `string` with `name =~ /password/`
|
457
|
+
`search` | `input[type=search]` | -
|
458
|
+
`text` | `textarea` | `text`
|
459
|
+
`file` | `input[type=file]` | `string` responding to file methods
|
460
|
+
`hidden` | `input[type=hidden]` | -
|
461
|
+
`integer` | `input[type=number]` | `integer`
|
462
|
+
`float` | `input[type=number]` | `float`
|
463
|
+
`decimal` | `input[type=number]` | `decimal`
|
464
|
+
`range` | `input[type=range]` | -
|
465
|
+
`datetime` | `select` | `datetime/timestamp`
|
466
|
+
`date` | `select` | `date`
|
467
|
+
`time` | `select` | `time`
|
468
|
+
`select` | `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations
|
469
|
+
`radio_buttons` | collection of `input[type=radio]` | `belongs_to` associations
|
470
|
+
`check_boxes` | collection of `input[type=checkbox]` | `has_many`/`has_and_belongs_to_many` associations
|
471
|
+
`country` | `select` (countries as options) | `string` with `name =~ /country/`
|
472
|
+
`time_zone` | `select` (timezones as options) | `string` with `name =~ /time_zone/`
|
466
473
|
|
467
474
|
## Custom inputs
|
468
475
|
|
@@ -483,6 +490,7 @@ And use it in your views:
|
|
483
490
|
```ruby
|
484
491
|
f.input :money, :as => :currency
|
485
492
|
```
|
493
|
+
Note, you may have to create the `app/inputs/` directory and restart your webserver.
|
486
494
|
|
487
495
|
You can also redefine existing **SimpleForm** inputs by creating a new class with the same name. For
|
488
496
|
instance, if you want to wrap date/time/datetime in a div, you can do:
|
@@ -4,12 +4,12 @@ module SimpleForm
|
|
4
4
|
desc "Copy SimpleForm default files"
|
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
|
-
class_option :bootstrap, :type => :boolean, :desc => 'Add the
|
7
|
+
class_option :bootstrap, :type => :boolean, :desc => 'Add the Bootstrap wrappers to the SimpleForm initializer.'
|
8
8
|
class_option :foundation, :type => :boolean, :desc => 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
|
9
9
|
|
10
10
|
def info_bootstrap
|
11
11
|
return if options.bootstrap? || options.foundation?
|
12
|
-
puts "SimpleForm 2 supports
|
12
|
+
puts "SimpleForm 2 supports Bootstrap and Zurb Foundation 3. 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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
===============================================================================
|
2
2
|
|
3
3
|
Be sure to have a copy of the Bootstrap stylesheet available on your
|
4
|
-
application, you can get it on http://
|
4
|
+
application, you can get it on http://getbootstrap.com/2.3.2/.
|
5
5
|
|
6
6
|
Inside your views, use the 'simple_form_for' with one of the Bootstrap form
|
7
7
|
classes, '.form-horizontal', '.form-inline', '.form-search' or
|
@@ -37,8 +37,8 @@ SimpleForm.setup do |config|
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
# Wrappers for forms and inputs using the
|
41
|
-
# Check the Bootstrap docs (http://
|
40
|
+
# Wrappers for forms and inputs using the Bootstrap toolkit.
|
41
|
+
# Check the Bootstrap docs (http://getbootstrap.com/2.3.2/)
|
42
42
|
# to learn about the different styles for forms and inputs,
|
43
43
|
# buttons and other elements.
|
44
44
|
config.default_wrapper = :bootstrap
|
@@ -178,7 +178,8 @@ module SimpleForm
|
|
178
178
|
|
179
179
|
# Append a hidden field to make sure something will be sent back to the
|
180
180
|
# server if all checkboxes are unchecked.
|
181
|
-
|
181
|
+
hidden_name = html_options[:name] || "#{object_name}[#{attribute}][]"
|
182
|
+
hidden = @template.hidden_field_tag(hidden_name, "", :id => nil)
|
182
183
|
|
183
184
|
wrap_rendered_collection(rendered_collection + hidden, options)
|
184
185
|
end
|
@@ -342,7 +342,7 @@ module SimpleForm
|
|
342
342
|
def lookup_model_names
|
343
343
|
@lookup_model_names ||= begin
|
344
344
|
child_index = options[:child_index]
|
345
|
-
names = object_name.to_s.scan(/(
|
345
|
+
names = object_name.to_s.scan(/(?!\d)\w+/).flatten
|
346
346
|
names.delete(child_index) if child_index
|
347
347
|
names.each { |name| name.gsub!('_attributes', '') }
|
348
348
|
names.freeze
|
@@ -17,6 +17,7 @@ module SimpleForm
|
|
17
17
|
input
|
18
18
|
elsif nested_boolean_style?
|
19
19
|
html_options = label_html_options.dup
|
20
|
+
html_options[:class] ||= []
|
20
21
|
html_options[:class].push(:checkbox)
|
21
22
|
|
22
23
|
build_hidden_field_for_checkbox +
|
@@ -34,7 +35,7 @@ module SimpleForm
|
|
34
35
|
# reuse the method for nested boolean style, but with no unchecked value,
|
35
36
|
# which won't generate the hidden checkbox. This is the default functionality
|
36
37
|
# in Rails > 3.2.1, and is backported in SimpleForm AV helpers.
|
37
|
-
def build_check_box(unchecked_value = unchecked_value)
|
38
|
+
def build_check_box(unchecked_value = unchecked_value())
|
38
39
|
@builder.check_box(attribute_name, input_html_options, checked_value, unchecked_value)
|
39
40
|
end
|
40
41
|
|
data/lib/simple_form/version.rb
CHANGED
@@ -288,6 +288,13 @@ class BuilderTest < ActionView::TestCase
|
|
288
288
|
assert_select "form input[type=hidden][name='user[tag_ids][]'][value=]", :count => 1
|
289
289
|
end
|
290
290
|
|
291
|
+
test "collection check box generates a hidden field using the given :name in :input_html" do
|
292
|
+
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
293
|
+
with_collection_check_boxes @user, :tag_ids, collection, :id, :name, {}, {:name => "user[other_tag_ids][]"}
|
294
|
+
|
295
|
+
assert_select "form input[type=hidden][name='user[other_tag_ids][]'][value=]", :count => 1
|
296
|
+
end
|
297
|
+
|
291
298
|
test "collection check box accepts a collection and generate a serie of checkboxes with labels for label method" do
|
292
299
|
collection = [Tag.new(1, 'Tag 1'), Tag.new(2, 'Tag 2')]
|
293
300
|
with_collection_check_boxes @user, :tag_ids, collection, :id, :name
|
@@ -79,6 +79,26 @@ class FormBuilderTest < ActionView::TestCase
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
test 'builder allow to use numbers in the model name' do
|
83
|
+
user = UserNumber1And2.new({
|
84
|
+
:id => 1,
|
85
|
+
:name => 'New in SimpleForm!',
|
86
|
+
:description => 'Hello!',
|
87
|
+
:created_at => Time.now
|
88
|
+
})
|
89
|
+
|
90
|
+
user.tags = [Tag.new(nil, 'Tag1')]
|
91
|
+
|
92
|
+
with_concat_form_for(user, :url => '/') do |f|
|
93
|
+
f.simple_fields_for(:tags) do |tags|
|
94
|
+
tags.input :name
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_select 'form .user_number1_and2_tags_name'
|
99
|
+
assert_no_select 'form .user_number1_and2_tags_1_name'
|
100
|
+
end
|
101
|
+
|
82
102
|
# INPUT TYPES
|
83
103
|
test 'builder should generate text fields for string columns' do
|
84
104
|
with_form_for @user, :name
|
@@ -137,4 +137,16 @@ class BooleanInputTest < ActionView::TestCase
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
test 'input boolean without additional classes should add "checkbox" class to label' do
|
142
|
+
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
143
|
+
swap SimpleForm, :boolean_style => :nested, :generate_additional_classes_for => [:input] do
|
144
|
+
with_input_for @user, :active, :boolean
|
145
|
+
|
146
|
+
assert_select 'label'
|
147
|
+
assert_select 'label.checkbox'
|
148
|
+
assert_no_select 'label.boolean'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
140
152
|
end
|
@@ -172,6 +172,12 @@ class CollectionSelectInputTest < ActionView::TestCase
|
|
172
172
|
assert_select 'select[required]'
|
173
173
|
end
|
174
174
|
|
175
|
+
test 'collection input with select type should generate required html attribute only with blank option or prompt' do
|
176
|
+
with_input_for @user, :name, :select, :prompt => 'Name...', :collection => ['Jose', 'Carlos']
|
177
|
+
assert_select 'select.required'
|
178
|
+
assert_select 'select[required]'
|
179
|
+
end
|
180
|
+
|
175
181
|
test 'collection input with select type should not generate required html attribute without blank option' do
|
176
182
|
with_input_for @user, :name, :select, :include_blank => false, :collection => ['Jose' , 'Carlos']
|
177
183
|
assert_select 'select.required'
|
data/test/support/models.rb
CHANGED
data/test/test_helper.rb
CHANGED
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.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project: simple_form
|
166
|
-
rubygems_version: 2.2.
|
166
|
+
rubygems_version: 2.2.3
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Forms made easy!
|