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:
- Go to create a node.
- Enter a value in the field collection.
- Click "Add Another".
- Enter another value in the field collection, different than the first.
- Click "Remove" on the first item.
- 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
Comment #1
jon pughComment #2
NVaissaud commentedHi 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.
Comment #3
harora commentedHello,
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
Comment #4
elijah lynnThis issue may have resolved this #2456307: Item Remove Button confuses #parents and #array_parents
Comment #5
elijah lynnThis appears to work in 7.x-1.0-beta8. Setting to needs review to see if anyone else can reproduce it.