Problem/Motivation

With a multi-valued field collection field on any form where #parents and #array_parents differ, the remove button appears to always remove the last item no matter which remove button is pressed.

To test this, create a form using the flexiform module and include a field collection field with multiple items. The remove button will appear to remove the wrong item.

Proposed resolution

#parents and #array_parents are different for a good reason! They let you put the submitted values in one place in the $form_state['values'] (#parents) and have the form element in a different location in the $form array (#array_parents). A module as popular as field collection should respect this difference!

Update the field_collection_remove_submit() function to respect the difference between #parents and #array_parents

Remaining tasks

- Review Patch

User interface changes

None

API changes

None

CommentFileSizeAuthor
#1 2456307-1.patch2.77 KBrlmumford

Comments

rlmumford’s picture

Status: Active » Needs review
StatusFileSize
new2.77 KB

Here's a patch.

I've added a variable called $values_address which is analogous to $address, but based on #parents instead of #array_parents. Whenever accessing or storing information in $form_state['values'] and $form_state['input'] I switch to using the $values_address and its derivatives.

rlmumford’s picture

Bump, Flexiform Module still requires this.

  • jmuzz committed 5af8373 on 8.x-1.x
    Completed the changes proposed by #2456307 and begun in #2613584
    

  • jmuzz committed 14076ef on 7.x-1.x authored by rlmumford
    Issue #2456307 by rlmumford: Item Remove Button confuses #parents and #...
jmuzz’s picture

Status: Needs review » Fixed

Thanks!

msmorais’s picture

I'm using version dev and even after applying the patch the problem continues

Status: Fixed » Closed (fixed)

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