Talk about an edge case...

I have no idea what's causing this.

For usability, I enclosed a field collection field in a collapsible fieldset using form alter.

Everything worked fine, or so I thought. Turns out, when you hit "remove", it always removes the last item, even if you hit "remove" on the first item.

Turns out is it not the fieldset at all, but the nested array.

To replicate, put this in a node_form_alter where "field_collection_field" is the name of your collection field with unlimited values:

  $form['custom_array'] = array(
    'field_collection_field' => $form['field_collection_field'],
  );
  unset($form['field_collection_field']);

Then:

  1. Go to create a node.
  2. Enter a value in the field collection.
  3. Click "Add Another".
  4. Enter another value in the field collection, different than the first.
  5. Click "Remove" on the first item.
  6. Watch the last item disappear.

I couldn't for the life of me figure out how to fix this, so I'm just going to work around it some how.

Comments

jon pugh’s picture

Issue summary: View changes
NVaissaud’s picture

Hi Jon,

I'm struggling with the same problem.
When i "add another" and delete some fc row item (not the last one), no one disappear.
Then if i save my content form, the last item of my fc has been removed.

At the opposite, when i load my full filled content form and i remove any fc row item, everything works fine.

This problem occurs only when you "add another" and want to remove some row at the same time.

Did you find any work around ?

Thank you.

harora’s picture

Hello,

Anyone got any solution to the problem.

I also changed the labels of remove buttons through form alter hook and remove button stopped behaving properly. It removes the last item always.

Any help on this would be greatly appreciated.

thank you

elijah lynn’s picture

elijah lynn’s picture

Status: Active » Needs review

This appears to work in 7.x-1.0-beta8. Setting to needs review to see if anyone else can reproduce it.