Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit e9958f7

Browse files
committed
Added RegEx to solve issues #26 and #30
1 parent 3c32e94 commit e9958f7

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

CHANGELOG.rdoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
0.1.0 (March 26, 2011)
1+
0.1.1 (April 18, 2011)
2+
3+
* Added new RegEx to generate new objects IDs correctly - issue #26 and issue #30
24

35
* Prefix new records with "new_" so there's no possible conflict with existing records - issue #21
46

README.rdoc

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This is a Rails gem for conveniently manage multiple nested models in a single f
44

55
This gem only works with Rails 3. See the {rails2 branch}[https://github.com/ryanb/nested_form/tree/rails2] for a plugin to work in Rails 2.
66

7+
== My fork
8+
9+
This forks solves issues #26 and #30.
710

811
== Setup
912

@@ -57,6 +60,8 @@ If you are using jQuery, <tt>nested:fieldAdded</tt> and <tt>nested:fieldRemoved<
5760

5861
== Special Thanks
5962

63+
First of all, thanks ro Ryan Bates for this gem. Awesome work.
64+
6065
This gem was originally based on the solution by Tim Riley in his {complex-form-examples fork}[https://github.com/timriley/complex-form-examples/tree/unobtrusive-jquery-deep-fix2].
6166

6267
Thank you Andrew Manshin for the Rails 3 transition, {Andrea Singh}[https://github.com/madebydna] for converting to a gem and {Peter Giacomo Lombardo}[https://github.com/pglombardo] for Prototype support.

lib/generators/nested_form/templates/jquery_nested_form.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ jQuery(function($) {
1818

1919
for(i = 0; i < parent_names.length; i++) {
2020
if(parent_ids[i]) {
21+
content = content.replace(
22+
new RegExp('(_' + parent_names[i] + ')_.+?_', 'g'),
23+
'$1_' + parent_ids[i] + '_');
24+
2125
content = content.replace(
2226
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
23-
'$1[' + parent_ids[i] + ']'
24-
)
27+
'$1[' + parent_ids[i] + ']');
2528
}
2629
}
2730
}

lib/generators/nested_form/templates/prototype_nested_form.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ document.observe('click', function(e, el) {
1717
var parent_ids = context.match(/(new_)?[0-9]+/g) || [];
1818

1919
for(i = 0; i < parent_names.length; i++) {
20-
if(parent_ids[i]) {
21-
content = content.replace(
22-
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
23-
'$1[' + parent_ids[i] + ']'
24-
)
25-
}
20+
if(parent_ids[i]) {
21+
content = content.replace(
22+
new RegExp('(_' + parent_names[i] + ')_.+?_', 'g'),
23+
'$1_' + parent_ids[i] + '_');
24+
25+
content = content.replace(
26+
new RegExp('(\\[' + parent_names[i] + '\\])\\[.+?\\]', 'g'),
27+
'$1[' + parent_ids[i] + ']');
28+
}
2629
}
2730
}
2831

0 commit comments

Comments
 (0)