diff --git a/README.md b/README.md
index 667b9dec..8f519447 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,9 @@
+## Speedway Special
+There are 2 differences between this and the main branch:
+
+1. A 'new_id' addition to the callback engine for adding fields so that way you can put them into tabs
+2. Modification to support inserting into a table when the last row of the table contains the link_to_add function
+
# Nested Form
[
](http://travis-ci.org/ryanb/nested_form)
diff --git a/vendor/assets/javascripts/jquery_nested_form.js b/vendor/assets/javascripts/jquery_nested_form.js
index 406c3051..b1f6862a 100644
--- a/vendor/assets/javascripts/jquery_nested_form.js
+++ b/vendor/assets/javascripts/jquery_nested_form.js
@@ -14,8 +14,11 @@
// Make the context correct by replacing with the generated ID
// of each of the parent objects
- var context = ($(link).closest('.fields').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(/\[[a-z_]+\]$/, '');
-
+ if($(link).data('tabled')){
+ var context = ($(link).closest('table').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(/\[[a-z_]+\]$/, '');
+ } else {
+ var context = ($(link).closest('.fields').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(/\[[a-z_]+\]$/, '');
+ }
// If the parent has no inputs we need to strip off the last pair
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'));
if (current) {
@@ -51,8 +54,8 @@
var field = this.insertFields(content, assoc, link);
// bubble up event upto document (through form)
field
- .trigger({ type: 'nested:fieldAdded', field: field })
- .trigger({ type: 'nested:fieldAdded:' + assoc, field: field });
+ .trigger({ type: 'nested:fieldAdded', field: field, new_id: new_id })
+ .trigger({ type: 'nested:fieldAdded:' + assoc, field: field, new_id: new_id });
return false;
},
newId: function() {
@@ -62,6 +65,8 @@
var target = $(link).data('target');
if (target) {
return $(content).appendTo($(target));
+ } else if ($(link).data('tabled')) {
+ return $(content).insertBefore($(link).closest('tr'))
} else {
return $(content).insertBefore(link);
}
diff --git a/vendor/assets/javascripts/prototype_nested_form.js b/vendor/assets/javascripts/prototype_nested_form.js
index 821d1a8d..7a30b936 100644
--- a/vendor/assets/javascripts/prototype_nested_form.js
+++ b/vendor/assets/javascripts/prototype_nested_form.js
@@ -8,8 +8,12 @@ document.observe('click', function(e, el) {
// Make the context correct by replacing with the generated ID
// of each of the parent objects
- var context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, '');
-
+ var context;
+ if (el.readAttribute('data-tabled')) {
+ context = (el.getOffsetParent('table').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, '');
+ } else {
+ context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, '');
+ }
// If the parent has no inputs we need to strip off the last pair
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'));
if (current) {
@@ -45,11 +49,13 @@ document.observe('click', function(e, el) {
var field;
if (target) {
field = $$(target)[0].insert(content);
+ } else if (el.readAttribute('data-tabled')) {
+ field = el.getOffsetParent('tr').insert({ before: content })
} else {
field = el.insert({ before: content });
}
- field.fire('nested:fieldAdded', {field: field});
- field.fire('nested:fieldAdded:' + assoc, {field: field});
+ field.fire('nested:fieldAdded', {field: field, new_id: new_id});
+ field.fire('nested:fieldAdded:' + assoc, {field: field, new_id: new_id});
return false;
}
});