nested_form_fields 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/assets/javascripts/nested_form_fields.js.coffee +2 -0
- data/lib/nested_form_fields.rb +4 -2
- data/lib/nested_form_fields/version.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: 7e9a9d80e8de459fc66f99524b4cd8745ee93f7b
|
4
|
+
data.tar.gz: 96091b9aac3a10ddf9cddc50f3ddd81b91610e07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55b8fe3a713f864adcceb97ceb0e6e976c52145fa3c93d855176d25725a83ff087e704783496703a4b135d5669fe9cb9b57091f2f645d6f4157cf3401c0df643
|
7
|
+
data.tar.gz: 3ad1d302024a32d97a5811f96821597d6069a88620824ec0c6bd85d3ced95d1c0614725a7d9e681af97ac67338bd38d08e043316c3d5f9762ac890ab5ea91143
|
data/README.md
CHANGED
@@ -177,6 +177,13 @@ $(document).on "fields_added.nested_form_fields", (event, param) ->
|
|
177
177
|
console.log "INFO: Fields were successfully added, callback not handled."
|
178
178
|
```
|
179
179
|
|
180
|
+
## Index replacement string
|
181
|
+
|
182
|
+
Sometimes your code needs to know what index it has when it is instantiated onto the page.
|
183
|
+
HTML data elements may need point to other form elements for instance. This is needed for integration
|
184
|
+
with rails3-jquery-autocomplete.
|
185
|
+
|
186
|
+
To enable string substitution with the current index use the magic string '__nested_field_for_replace_with_index__'
|
180
187
|
|
181
188
|
## Contributing
|
182
189
|
|
@@ -19,6 +19,8 @@ nested_form_fields.bind_nested_forms_links = () ->
|
|
19
19
|
# insert association indexes
|
20
20
|
index_placeholder = "__#{association_path}_index__"
|
21
21
|
template_html = template_html.replace(new RegExp(index_placeholder,"g"), added_index)
|
22
|
+
# look for replacements in user defined code and substitute with the index
|
23
|
+
template_html = template_html.replace(new RegExp("__nested_field_for_replace_with_index__","g"), added_index)
|
22
24
|
|
23
25
|
# replace child template div tags with script tags to avoid form submission of templates
|
24
26
|
$parsed_template = $(template_html)
|
data/lib/nested_form_fields.rb
CHANGED
@@ -69,13 +69,15 @@ module ActionView::Helpers
|
|
69
69
|
end
|
70
70
|
|
71
71
|
output = ActiveSupport::SafeBuffer.new
|
72
|
-
association.
|
72
|
+
association.each_with_index do |child, index|
|
73
73
|
wrapper_options = options[:wrapper_options].clone || {}
|
74
74
|
if child._destroy == true
|
75
75
|
wrapper_options[:style] = wrapper_options[:style] ? wrapper_options[:style] + ';' + 'display:none' : 'display:none'
|
76
76
|
end
|
77
77
|
output << nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend], wrapper_options) do
|
78
|
-
fields_for_nested_model("#{name}[#{options[:child_index] || nested_child_index(name)}]", child, options, block)
|
78
|
+
new_block = fields_for_nested_model("#{name}[#{options[:child_index] || nested_child_index(name)}]", child, options, block)
|
79
|
+
# do substitution in user defined blocks with the current index allows JS functions to have proper references
|
80
|
+
new_block.gsub('__nested_field_for_replace_with_index__', index.to_s).html_safe
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_form_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nico Ritsche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
version: '0'
|
273
273
|
requirements: []
|
274
274
|
rubyforge_project:
|
275
|
-
rubygems_version: 2.
|
275
|
+
rubygems_version: 2.5.1
|
276
276
|
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Rails gem for dynamically adding and removing nested has_many association
|