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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6508541d7bf141ed4e6d5bb94b113ee153becb1
4
- data.tar.gz: a482dd6c7f7aaa78bd3f316ee2b1b7065f2c9bb1
3
+ metadata.gz: 7e9a9d80e8de459fc66f99524b4cd8745ee93f7b
4
+ data.tar.gz: 96091b9aac3a10ddf9cddc50f3ddd81b91610e07
5
5
  SHA512:
6
- metadata.gz: 854bd9ddacd3ba7167247f5fbba680aab9d52371ca192be2ecbdad18412a922df96c0032c66e1cdf2d60f0da4b8aa3794b046ce18f3c1d979a16cdb3ee00c6c9
7
- data.tar.gz: 2ba62dba2025e5aba5386f1b665f5afcc815251fe07913858849997c1ba584113f9b7a234f0f2c9bcc2e19adce03a08d1a67e04f914458b764df0908f553624a
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)
@@ -69,13 +69,15 @@ module ActionView::Helpers
69
69
  end
70
70
 
71
71
  output = ActiveSupport::SafeBuffer.new
72
- association.each do |child|
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
 
@@ -1,3 +1,3 @@
1
1
  module NestedFormFields
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
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.6
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-04-13 00:00:00.000000000 Z
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.4.6
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