nested_form_fields 0.7.7 → 0.8.3

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
- SHA1:
3
- metadata.gz: 7e9a9d80e8de459fc66f99524b4cd8745ee93f7b
4
- data.tar.gz: 96091b9aac3a10ddf9cddc50f3ddd81b91610e07
2
+ SHA256:
3
+ metadata.gz: cd4df0cf94166b6a42a70a0676168960735f6fd92d1cc07ba6c942495e4042e2
4
+ data.tar.gz: de6ca1333d9d98c2a965c1526c6cf17c43ccf617000cabbed1d279ab04c2fdb6
5
5
  SHA512:
6
- metadata.gz: 55b8fe3a713f864adcceb97ceb0e6e976c52145fa3c93d855176d25725a83ff087e704783496703a4b135d5669fe9cb9b57091f2f645d6f4157cf3401c0df643
7
- data.tar.gz: 3ad1d302024a32d97a5811f96821597d6069a88620824ec0c6bd85d3ced95d1c0614725a7d9e681af97ac67338bd38d08e043316c3d5f9762ac890ab5ea91143
6
+ metadata.gz: d91f11f1dadf41e12edd49d63a2eee4d126ceace8e0cf93eb6d595e2db28245ea61dbab4bffcf4ddf4307d816cda9e3ae08f33a2932056e3f512dbb3c9de9770
7
+ data.tar.gz: ec662c27318ba48fff3ef627fd94529a25872bca7c15e170640236be537657ff577b6d47838a5b2603d27284a7d8aeafde0198bac56287fd1a9acd2e2f66777c
@@ -1,10 +1,10 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
3
  - 2.1.7
5
4
  - 2.2.3
5
+ - 2.3.2
6
6
 
7
- before_install: gem install bundler -v 1.11.2
7
+ before_install: gem install bundler -v 1.11.2
8
8
 
9
9
  before_script:
10
10
  - "export DISPLAY=:99.0"
data/README.md CHANGED
@@ -14,15 +14,44 @@ It uses jQuery to dynamically add and remove nested associations.
14
14
 
15
15
  Add this line to your application's Gemfile:
16
16
 
17
- gem 'nested_form_fields'
17
+ ```ruby
18
+ gem 'nested_form_fields'
19
+ ```
18
20
 
19
21
  And then execute:
20
22
 
21
- $ bundle
23
+ ```console
24
+ $ bundle
25
+ ```
22
26
 
23
27
  In your application.js file add:
24
28
 
25
- //= require nested_form_fields
29
+ ```javascript
30
+ //= require nested_form_fields
31
+ ```
32
+
33
+ ### Rails 5.1+
34
+
35
+ You will need to install jQuery as Rails dropped it from its default stack.
36
+
37
+ Add to Gemfile:
38
+
39
+ ```ruby
40
+ gem 'jquery-rails'
41
+ ```
42
+
43
+ Execute:
44
+
45
+ ```console
46
+ $ bundle
47
+ ```
48
+
49
+ Add to application.js:
50
+
51
+ ```javascript
52
+ //= require jquery3
53
+ //= require jquery_ujs
54
+ ```
26
55
 
27
56
  ## Usage
28
57
 
@@ -80,7 +109,7 @@ f.add_nested_fields_link :videos, 'Add another funtastic video', class: 'btn btn
80
109
  You can supply a block to the `remove_nested_fields_link` and the `add_nested_fields_link` helpers, as you can with `link_to`:
81
110
 
82
111
  ```haml
83
- = ff.remove_nested_fields_link
112
+ = ff.remove_nested_fields_link do
84
113
  Remove me %span.icon-trash
85
114
  ```
86
115
 
@@ -141,8 +170,8 @@ def user_params
141
170
  params.require(:user)
142
171
  .permit(:name,:email,videos_attributes:[:video_title,:_destroy,:id])
143
172
  # ^^^ ^^^ ^^^
144
- # nested model attrs
145
- # they will let you delete the nested model
173
+ # nested model attrs
174
+ # they will let you delete the nested model
146
175
  end
147
176
  ```
148
177
 
@@ -177,13 +206,24 @@ $(document).on "fields_added.nested_form_fields", (event, param) ->
177
206
  console.log "INFO: Fields were successfully added, callback not handled."
178
207
  ```
179
208
 
209
+ You can pass any additional data to the event's callback. This may be useful if you trigger them programmatically. Example:
210
+
211
+ ```coffeescript
212
+ # Trigger button click programmatically and pass an object `{hello: 'world'}`
213
+ $('.add_nested_fields_link').trigger('click', [{hello: 'world'}])
214
+
215
+ # Listen for the event
216
+ $(document).on "fields_added.nested_form_fields", (event, param) ->
217
+ console.log param.additional_data #=> {hello: 'world'}
218
+ ```
219
+
180
220
  ## Index replacement string
181
221
 
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.
222
+ Sometimes your code needs to know what index it has when it is instantiated onto the page.
223
+ HTML data elements may need to point to other form elements for instance. This is needed for integration
224
+ with rails3-jquery-autocomplete.
185
225
 
186
- To enable string substitution with the current index use the magic string '__nested_field_for_replace_with_index__'
226
+ To enable string substitution with the current index use the magic string `__nested_field_for_replace_with_index__`.
187
227
 
188
228
  ## Contributing
189
229
 
@@ -2,12 +2,12 @@ window.nested_form_fields or= {}
2
2
 
3
3
  nested_form_fields.bind_nested_forms_links = () ->
4
4
  $('body').off("click", '.add_nested_fields_link')
5
- $('body').on 'click', '.add_nested_fields_link', (event) ->
5
+ $('body').on 'click', '.add_nested_fields_link', (event, additional_data) ->
6
6
  $link = $(this)
7
7
  object_class = $link.data('object-class')
8
8
  association_path = $link.data('association-path')
9
9
  added_index = $(".nested_#{association_path}").length
10
- $.event.trigger("fields_adding.nested_form_fields",{object_class: object_class, added_index: added_index, association_path: association_path});
10
+ $.event.trigger("fields_adding.nested_form_fields",{object_class: object_class, added_index: added_index, association_path: association_path, additional_data: additional_data});
11
11
  if $link.data('scope')
12
12
  $template = $("#{$link.data('scope')} ##{association_path}_template")
13
13
  else
@@ -33,13 +33,13 @@ nested_form_fields.bind_nested_forms_links = () ->
33
33
  $('#' + target).append($parsed_template)
34
34
  else
35
35
  $template.before( $parsed_template )
36
- $parsed_template.trigger("fields_added.nested_form_fields", {object_class: object_class, added_index: added_index, association_path: association_path, event: event});
36
+ $parsed_template.trigger("fields_added.nested_form_fields", {object_class: object_class, added_index: added_index, association_path: association_path, event: event, additional_data: additional_data});
37
37
  false
38
38
 
39
39
  $('body').off("click", '.remove_nested_fields_link')
40
40
  $('body').on 'click', '.remove_nested_fields_link', ->
41
41
  $link = $(this)
42
- return false unless $.rails.allowAction($link)
42
+ return false unless $.rails == undefined || $.rails.allowAction($link)
43
43
  object_class = $link.data('object-class')
44
44
  delete_association_field_name = $link.data('delete-association-field-name')
45
45
  removed_index = parseInt(delete_association_field_name.match('(\\d+\\]\\[_destroy])')[0].match('\\d+')[0])
@@ -51,7 +51,7 @@ nested_form_fields.bind_nested_forms_links = () ->
51
51
  else
52
52
  $nested_fields_container.before "<input type='hidden' name='#{delete_association_field_name}' value='1' />"
53
53
  $nested_fields_container.hide()
54
- $nested_fields_container.find('input[required]:hidden').removeAttr('required')
54
+ $nested_fields_container.find('input[required]:hidden, select[required]:hidden, textarea[required]:hidden').removeAttr('required')
55
55
  $nested_fields_container.trigger("fields_removed.nested_form_fields",{object_class: object_class, delete_association_field_name: delete_association_field_name, removed_index: removed_index});
56
56
  false
57
57
 
@@ -73,12 +73,14 @@ module ActionView::Helpers
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
+ output << destroy_hidden_field(association_name, index)
76
77
  end
77
- output << nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend], wrapper_options) do
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
78
+
79
+ # Build the wrapper + content and do substitution with the current index allows JS functions to have proper references
80
+ wrapped_block = nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend], wrapper_options) do
81
+ fields_for_nested_model("#{name}[#{options[:child_index] || nested_child_index(name)}]", child, options, block)
81
82
  end
83
+ output << wrapped_block.gsub('__nested_field_for_replace_with_index__', index.to_s).html_safe
82
84
  end
83
85
 
84
86
  output << nested_model_template(name, association_name, options, block)
@@ -114,7 +116,7 @@ module ActionView::Helpers
114
116
  end
115
117
 
116
118
  def association_path association_name
117
- "#{object_name.gsub('][','_').gsub(/_attributes/,'').sub('[','_').sub(']','')}_#{association_name}"
119
+ "#{object_name.to_s.gsub('][','_').gsub(/_attributes/,'').sub('[','_').sub(']','')}_#{association_name}"
118
120
  end
119
121
 
120
122
  def index_placeholder association_name
@@ -132,6 +134,11 @@ module ActionView::Helpers
132
134
  end
133
135
  end
134
136
 
137
+ def destroy_hidden_field(association_name, index)
138
+ @template.hidden_field "#{object_name}[#{association_name}_attributes][#{index}]",
139
+ :_destroy, value: 1
140
+ end
141
+
135
142
  def add_default_classes_to_wrapper_options(association_name, wrapper_options)
136
143
  default_classes = ["nested_fields", "nested_#{association_path(association_name)}"]
137
144
  wrapper_options[:class] = wrapper_options[:class].is_a?(String) ? wrapper_options[:class].split(" ") : wrapper_options[:class].to_a
@@ -1,3 +1,3 @@
1
1
  module NestedFormFields
2
- VERSION = "0.7.7"
2
+ VERSION = "0.8.3"
3
3
  end
@@ -21,13 +21,16 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'coffee-rails', '>= 3.2.1'
22
22
  gem.add_dependency 'jquery-rails'
23
23
 
24
- gem.add_development_dependency 'rspec-rails', '~> 2.9'
24
+ gem.add_development_dependency 'rspec-rails', '~> 3.5'
25
+ gem.add_development_dependency 'nokogiri', '1.6.8.1'
25
26
  gem.add_development_dependency 'assert_difference'
26
27
  gem.add_development_dependency 'capybara'
27
- gem.add_development_dependency 'selenium-webdriver'
28
- gem.add_development_dependency 'sqlite3'
28
+ gem.add_development_dependency 'geckodriver-helper'
29
+ gem.add_development_dependency 'selenium-webdriver', '> 3.0.5'
30
+ gem.add_development_dependency 'sqlite3', '~> 1.3.6'
29
31
  gem.add_development_dependency 'haml', '>= 3.1.5'
30
- gem.add_development_dependency 'haml-rails'
32
+ gem.add_development_dependency 'haml-rails', '~> 0.4.0'
31
33
  gem.add_development_dependency 'sass-rails', '~> 3.2.3'
32
34
  gem.add_development_dependency 'test-unit', '1.2.3'
35
+ gem.add_development_dependency 'public_suffix', '~> 1.4.6'
33
36
  end
@@ -9,6 +9,10 @@ ENV["RAILS_ENV"] = 'test'
9
9
  require_relative "dummy/config/environment"
10
10
 
11
11
  require 'rspec/rails'
12
+
13
+ # prevent Test::Unit's AutoRunner from executing during RSpec's rake task see https://github.com/rspec/rspec-rails/issues/1171
14
+ Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
15
+
12
16
  require 'assert_difference'
13
17
  require 'sqlite3'
14
18
 
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.7
4
+ version: 0.8.3
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-05-06 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,14 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.9'
61
+ version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.9'
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.8.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.8.1
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: assert_difference
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: selenium-webdriver
112
+ name: geckodriver-helper
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -108,20 +122,34 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: selenium-webdriver
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">"
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.5
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">"
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.5
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: sqlite3
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - ">="
143
+ - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: '0'
145
+ version: 1.3.6
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - ">="
150
+ - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: '0'
152
+ version: 1.3.6
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: haml
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +168,16 @@ dependencies:
140
168
  name: haml-rails
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
- - - ">="
171
+ - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: '0'
173
+ version: 0.4.0
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
- - - ">="
178
+ - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: '0'
180
+ version: 0.4.0
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: sass-rails
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +206,20 @@ dependencies:
178
206
  - - '='
179
207
  - !ruby/object:Gem::Version
180
208
  version: 1.2.3
209
+ - !ruby/object:Gem::Dependency
210
+ name: public_suffix
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 1.4.6
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 1.4.6
181
223
  description: |-
182
224
  Rails gem for dynamically adding and removing nested has_many association fields in a form.
183
225
  Uses jQuery and supports multiple nesting levels. Requires Ruby 1.9+ and the asset pipeline.
@@ -194,8 +236,6 @@ files:
194
236
  - LICENSE
195
237
  - README.md
196
238
  - Rakefile
197
- - lib/assets/.DS_Store
198
- - lib/assets/javascripts/.DS_Store
199
239
  - lib/assets/javascripts/nested_form_fields.js.coffee
200
240
  - lib/nested_form_fields.rb
201
241
  - lib/nested_form_fields/version.rb
@@ -271,8 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
311
  - !ruby/object:Gem::Version
272
312
  version: '0'
273
313
  requirements: []
274
- rubyforge_project:
275
- rubygems_version: 2.5.1
314
+ rubygems_version: 3.0.4
276
315
  signing_key:
277
316
  specification_version: 4
278
317
  summary: Rails gem for dynamically adding and removing nested has_many association