Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Created February 25, 2011 07:58
Show Gist options
  • Save michaeltwofish/843506 to your computer and use it in GitHub Desktop.
Save michaeltwofish/843506 to your computer and use it in GitHub Desktop.
// Handle attaching children
$('#unattached_children a.add').click(function() {
var icons = $(this).parent();
var child_type = // work out what the name of the child is
// Update label text
$('#attached_children>label').html('Attached '+child_type);
// Move the item to the attached items list
$('#AttachedItems .list').append($(this).closest('.item'));
$('#attached_children .list .item:last-child').append('<input name="'+child_type+'[]" type="hidden" value="'+$('#attached_children .list .item:last-child').attr('id')+'" />');
// Fix the icons
$(this).parent().empty();
icons.append('<a href="#" class="delete">Delete</a>').click(function() {
$(this).closest('.item').remove();
return false;
});
icons.append('<a href="#" class="move">Move</a>');
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment