Module works great when editing a node, but it doesn't work when creating a new one and using field collection. Clicking on a Remove-Button just reloads the page.

Steps to reproduce:
1. Create a node type YOURTYPE with a field collection
2. Attach an image field with unlimited values to the field collection
3. Go to http://www.example.com/node/add/YOURTYPE
4. Add some images to the image field (i used filefield sources for this)
5. Try to remove one image => page will be reloaded

CommentFileSizeAuthor
#3 1370396.patch1.78 KBswentel

Comments

labor b’s picture

I did some further testing on a clean install and managed to fix this issue.
It works when I put drupal_add_js into a hook_init or hook_form_alter function.

I'm not that familiar with Drupal.behaviors, but it seems like the function has to be present before adding new files.

labor b’s picture

Don't think my solution is best practice, but in case someone needs a quick fix:

/**
 * Implements hook_init().
 */
function files_undo_remove_init() {
  drupal_add_js(drupal_get_path('module', 'files_undo_remove').'/files_undo_remove.js');
}

Just attach this to files_undo_remove.module.

swentel’s picture

Status: Active » Fixed
StatusFileSize
new1.78 KB

Here's a patch. I've moved the css and js file to the hook_init(), because this would also fail on an existing node edit which has no files attached yet.
While hook_init() is kind of annoying in a way, there's no other place (well, maybe attach_form or so, but still). With css and js aggregation on, this is not really a big penalty. I'll put out a new release soon!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.