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

JavaScript bug when the parent of a nested attribute is not in a "many" relationship. #19

Merged
merged 2 commits into from
Mar 26, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/generators/nested_form/templates/jquery_nested_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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;
});

Expand All @@ -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;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down