diff --git a/lib/generators/nested_form/templates/jquery_nested_form.js b/lib/generators/nested_form/templates/jquery_nested_form.js index 5a805f11..7c4bae4b 100644 --- a/lib/generators/nested_form/templates/jquery_nested_form.js +++ b/lib/generators/nested_form/templates/jquery_nested_form.js @@ -14,7 +14,7 @@ $('form a.add_nested_fields').live('click', function() { // project[tasks_attributes][0][assignments_attributes][1] if(context) { var parent_names = context.match(/[a-z_]+_attributes/g) || []; - var parent_ids = context.match(/[0-9]+/g); + var parent_ids = context.match(/[0-9]+/g) || []; for(i = 0; i < parent_names.length; i++) { if(parent_ids[i]) { @@ -32,6 +32,7 @@ $('form a.add_nested_fields').live('click', function() { content = content.replace(regexp, new_id); $(this).before(content); + $(this).closest("form").trigger('nested:fieldAdded'); return false; }); @@ -41,6 +42,7 @@ $('form a.remove_nested_fields').live('click', function() { hidden_field.value = '1'; } $(this).closest('.fields').hide(); + $(this).closest("form").trigger('nested:fieldRemoved'); return false; }); }); \ No newline at end of file diff --git a/lib/generators/nested_form/templates/prototype_nested_form.js b/lib/generators/nested_form/templates/prototype_nested_form.js index 8386b8ec..59c42f6f 100644 --- a/lib/generators/nested_form/templates/prototype_nested_form.js +++ b/lib/generators/nested_form/templates/prototype_nested_form.js @@ -14,7 +14,7 @@ document.observe('click', function(e, el) { // project[tasks_attributes][0][assignments_attributes][1] if(context) { var parent_names = context.match(/[a-z_]+_attributes/g) || []; - var parent_ids = context.match(/[0-9]+/g); + var parent_ids = context.match(/[0-9]+/g) || []; for(i = 0; i < parent_names.length; i++) { if(parent_ids[i]) {