nested_form_fields 0.0.7 → 0.0.8
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/README.md +18 -0
- data/lib/nested_form_fields.rb +7 -7
- data/lib/nested_form_fields/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -52,6 +52,19 @@ Links to add and remove fields can be added using the *add_nested_fields_link* a
|
|
52
52
|
|
53
53
|
Note that *remove_nested_fields_link* needs to be called within the *nested_fields_for* call and *add_nested_fields_link* outside of it via the parent builder.
|
54
54
|
|
55
|
+
You can change the link text of *remove_nested_fields_link* and *add_nested_fields_link* like this:
|
56
|
+
|
57
|
+
...
|
58
|
+
ff.remove_nested_fields_link 'Remove me'
|
59
|
+
...
|
60
|
+
f.add_nested_fields_link :videos, 'Add another funtastic video'
|
61
|
+
|
62
|
+
You can change the type of the element wrapping the nested fields using the *wrapper* option:
|
63
|
+
|
64
|
+
= f.nested_fields_for :videos, wrapper: :div do |ff|
|
65
|
+
|
66
|
+
The default wrapper element is a fieldset.
|
67
|
+
|
55
68
|
|
56
69
|
## Contributing
|
57
70
|
|
@@ -60,3 +73,8 @@ Note that *remove_nested_fields_link* needs to be called within the *nested_fiel
|
|
60
73
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
61
74
|
4. Push to the branch (`git push origin my-new-feature`)
|
62
75
|
5. Create new Pull Request
|
76
|
+
|
77
|
+
|
78
|
+
## Contributers
|
79
|
+
|
80
|
+
[Tom Riley](https://github.com/tomriley)
|
data/lib/nested_form_fields.rb
CHANGED
@@ -15,6 +15,7 @@ module ActionView::Helpers
|
|
15
15
|
fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
|
16
16
|
fields_options[:builder] ||= options[:builder]
|
17
17
|
fields_options[:parent_builder] = self
|
18
|
+
fields_options[:wrapper] ||= :fieldset
|
18
19
|
fields_options[:namespace] = fields_options[:parent_builder].options[:namespace]
|
19
20
|
|
20
21
|
return fields_for_has_many_association_with_template(record_name, record_object, fields_options, block)
|
@@ -46,11 +47,10 @@ module ActionView::Helpers
|
|
46
47
|
association = @object.send(association_name)
|
47
48
|
end
|
48
49
|
|
49
|
-
explicit_child_index = options[:child_index]
|
50
50
|
output = ActiveSupport::SafeBuffer.new
|
51
51
|
association.each do |child|
|
52
|
-
output << nested_fields_wrapper(association_name) do
|
53
|
-
fields_for_nested_model("#{name}[#{
|
52
|
+
output << nested_fields_wrapper(association_name, options[:wrapper]) do
|
53
|
+
fields_for_nested_model("#{name}[#{options[:child_index] || nested_child_index(name)}]", child, options, block)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -61,7 +61,7 @@ module ActionView::Helpers
|
|
61
61
|
|
62
62
|
def nested_model_template name, association_name, options, block
|
63
63
|
for_template = self.options[:for_template]
|
64
|
-
|
64
|
+
|
65
65
|
# Render the outermost template in a script tag to avoid it from being submited with the form
|
66
66
|
# Render all deeper nested templates as hidden divs as nesting script tags messes up the html.
|
67
67
|
# When nested fields are added with javascript by using a template that contains nested templates,
|
@@ -73,7 +73,7 @@ module ActionView::Helpers
|
|
73
73
|
id: template_id(association_name),
|
74
74
|
class: for_template ? 'form_template' : nil,
|
75
75
|
style: for_template ? 'display:none' : nil ) do
|
76
|
-
nested_fields_wrapper(association_name) do
|
76
|
+
nested_fields_wrapper(association_name, options[:wrapper]) do
|
77
77
|
fields_for_nested_model("#{name}[#{index_placeholder(association_name)}]",
|
78
78
|
association_name.to_s.classify.constantize.new,
|
79
79
|
options.merge(for_template: true), block)
|
@@ -99,8 +99,8 @@ module ActionView::Helpers
|
|
99
99
|
end
|
100
100
|
|
101
101
|
|
102
|
-
def nested_fields_wrapper association_name
|
103
|
-
@template.content_tag
|
102
|
+
def nested_fields_wrapper association_name, wrapper_element_type
|
103
|
+
@template.content_tag wrapper_element_type, class: "nested_fields nested_#{association_path(association_name)}" do
|
104
104
|
yield
|
105
105
|
end
|
106
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_form_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-24 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "Rails gem for dynamically adding and removing nested has_many association
|
15
15
|
fields in a form.\n Uses jQuery and supports multiple nesting
|