nested_form 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +9 -2
- data/Rakefile +4 -2
- data/lib/nested_form/builder_mixin.rb +4 -8
- data/lib/nested_form/view_helper.rb +3 -2
- data/spec/dummy/app/assets/javascripts/jquery.js +2426 -2003
- data/spec/dummy/app/assets/javascripts/jquery_nested_form.js +1 -33
- data/spec/dummy/app/models/task.rb +2 -0
- data/spec/dummy/app/views/projects/new.html.erb +8 -3
- data/spec/dummy/config/boot.rb +2 -2
- data/spec/form_spec.rb +8 -0
- data/vendor/assets/javascripts/jquery_nested_form.js +1 -33
- metadata +2 -2
@@ -13,8 +13,7 @@ jQuery(function($) {
|
|
13
13
|
|
14
14
|
// Make the context correct by replacing new_<parents> with the generated ID
|
15
15
|
// of each of the parent objects
|
16
|
-
var context = ($(link).closest('.fields').
|
17
|
-
|
16
|
+
var context = ($(link).closest('.fields').find('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
|
18
17
|
|
19
18
|
// context will be something like this for a brand new form:
|
20
19
|
// project[tasks_attributes][new_1255929127459][assignments_attributes][new_1255929128105]
|
@@ -70,34 +69,3 @@ jQuery(function($) {
|
|
70
69
|
$('form a.add_nested_fields').live('click', nestedFormEvents.addFields);
|
71
70
|
$('form a.remove_nested_fields').live('click', nestedFormEvents.removeFields);
|
72
71
|
});
|
73
|
-
|
74
|
-
|
75
|
-
// http://plugins.jquery.com/project/closestChild
|
76
|
-
/*
|
77
|
-
* Copyright 2011, Tobias Lindig
|
78
|
-
*
|
79
|
-
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
80
|
-
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
81
|
-
*
|
82
|
-
*/
|
83
|
-
(function($) {
|
84
|
-
$.fn.closestChild = function(selector) {
|
85
|
-
// breadth first search for the first matched node
|
86
|
-
if (selector && selector != '') {
|
87
|
-
var queue = [];
|
88
|
-
queue.push(this);
|
89
|
-
while(queue.length > 0) {
|
90
|
-
var node = queue.shift();
|
91
|
-
var children = node.children();
|
92
|
-
for(var i = 0; i < children.length; ++i) {
|
93
|
-
var child = $(children[i]);
|
94
|
-
if (child.is(selector)) {
|
95
|
-
return child; //well, we found one
|
96
|
-
}
|
97
|
-
queue.push(child);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
return $();//nothing found
|
102
|
-
};
|
103
|
-
})(jQuery);
|
@@ -6,9 +6,14 @@
|
|
6
6
|
|
7
7
|
<%= nested_form_for @project do |f| -%>
|
8
8
|
<%= f.text_field :name %>
|
9
|
-
<%= f.fields_for :tasks do |
|
10
|
-
<%=
|
11
|
-
<%=
|
9
|
+
<%= f.fields_for :tasks do |tf| -%>
|
10
|
+
<%= tf.text_field :name %>
|
11
|
+
<%= tf.fields_for :milestones do |mf| %>
|
12
|
+
<%= mf.text_field :name %>
|
13
|
+
<%= mf.link_to_remove 'Remove milestone' %>
|
14
|
+
<% end %>
|
15
|
+
<%= tf.link_to_add 'Add new milestone', :milestones %>
|
16
|
+
<%= tf.link_to_remove 'Remove' %>
|
12
17
|
<% end -%>
|
13
18
|
<%= f.link_to_add 'Add new task', :tasks %>
|
14
19
|
<% end -%>
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
gemfile = ENV['BUNDLE_GEMFILE'] || File.expand_path('../../../../
|
3
|
+
gemfile = ENV['BUNDLE_GEMFILE'] || File.expand_path('../../../../Gemfile', __FILE__)
|
4
4
|
if File.exist?(gemfile)
|
5
5
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
6
6
|
require 'bundler'
|
7
7
|
Bundler.setup
|
8
8
|
end
|
9
9
|
|
10
|
-
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
10
|
+
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
data/spec/form_spec.rb
CHANGED
@@ -30,4 +30,12 @@ describe 'NestedForm' do
|
|
30
30
|
visit '/projects/new?type=prototype'
|
31
31
|
check_form
|
32
32
|
end
|
33
|
+
|
34
|
+
it 'generates correct name for the nested input', :js => true do
|
35
|
+
visit '/projects/new?type=jquery'
|
36
|
+
click_link 'Add new task'
|
37
|
+
click_link 'Add new milestone'
|
38
|
+
name = find('.fields .fields input[id$=name]')[:name]
|
39
|
+
name.should match(/\Aproject\[tasks_attributes\]\[new_\d+\]\[milestones_attributes\]\[new_\d+\]\[name\]\z/)
|
40
|
+
end
|
33
41
|
end
|
@@ -13,8 +13,7 @@ jQuery(function($) {
|
|
13
13
|
|
14
14
|
// Make the context correct by replacing new_<parents> with the generated ID
|
15
15
|
// of each of the parent objects
|
16
|
-
var context = ($(link).closest('.fields').
|
17
|
-
|
16
|
+
var context = ($(link).closest('.fields').find('input:first').attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), '');
|
18
17
|
|
19
18
|
// context will be something like this for a brand new form:
|
20
19
|
// project[tasks_attributes][new_1255929127459][assignments_attributes][new_1255929128105]
|
@@ -70,34 +69,3 @@ jQuery(function($) {
|
|
70
69
|
$('form a.add_nested_fields').live('click', nestedFormEvents.addFields);
|
71
70
|
$('form a.remove_nested_fields').live('click', nestedFormEvents.removeFields);
|
72
71
|
});
|
73
|
-
|
74
|
-
|
75
|
-
// http://plugins.jquery.com/project/closestChild
|
76
|
-
/*
|
77
|
-
* Copyright 2011, Tobias Lindig
|
78
|
-
*
|
79
|
-
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
80
|
-
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
81
|
-
*
|
82
|
-
*/
|
83
|
-
(function($) {
|
84
|
-
$.fn.closestChild = function(selector) {
|
85
|
-
// breadth first search for the first matched node
|
86
|
-
if (selector && selector != '') {
|
87
|
-
var queue = [];
|
88
|
-
queue.push(this);
|
89
|
-
while(queue.length > 0) {
|
90
|
-
var node = queue.shift();
|
91
|
-
var children = node.children();
|
92
|
-
for(var i = 0; i < children.length; ++i) {
|
93
|
-
var child = $(children[i]);
|
94
|
-
if (child.is(selector)) {
|
95
|
-
return child; //well, we found one
|
96
|
-
}
|
97
|
-
queue.push(child);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
return $();//nothing found
|
102
|
-
};
|
103
|
-
})(jQuery);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|