I have a multifield with unlimited "number of values".

If I create a node, add several multifield values, save it, edit it, and click remove on each value every value get removed apart from the last one.

What I'd expect to happen is for the final value to be removed and instead for it to show empty (or default value) subfields.

Comments

Tilo Schumann’s picture

Same problem here. I cannot remove last (id est "first") item.

When I add a new (empty) item, place it first and delete the old one I get:

Error: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'fid' cannot be null: ...

Tested versions: 7.x-1.0-alpha1 and 7.x-1.x-dev

Update:

Meanwhile I see, you have to empty all fields of the "last" item by yourself.

My sites runs into an error, when you remove a file, but forget to reset a radio-Button. I have to prevent this by a validation-handler.
Perhaps you can solve that problem in one of the next updates.

Thank you

kyle.veldhuizen’s picture

I am also having this issue.

chrisrockwell’s picture

I'm able to reproduce this using alpha3 and dev in my current project. I also did a clean install on simplytest.me and got the same result. I'm looking through the tests now and will try to create one that reproduces this.

chrisrockwell’s picture

I'm not sure if this helps but...If you have, for example, a select list in your multifield do the following:
1. Edit the entity
2. Remove all but one of the multiple value multifields.
3. Change the value of the select list in the remaining field
4. Click "Remove"

This will result in the select list resetting itself to the original value, instead of deleting the element. I've just found time to work on this so I'm digging in now.

chrisrockwell’s picture

I have more information, unfortunately it doesn't get me any closer to solving it.

Another issue with the remove button is when the following happens:

  1. Add 3 items to the multiple field and save
  2. Edit the entity and delete the first or second item
  3. Notice that the 3rd item is moved to the first position (if the 1st element is deleted, 3 => 1, 2 => 2). The expected behavior would be that 2 => 1, 3 => 2

Within multifield.field.inc the comments indicate the code was copied from field_collection.module. However, the code in question has since been patched due to https://www.drupal.org/node/1675522. The committed patch is: http://cgit.drupalcode.org/field_collection/commit/?id=d797efa

chrisrockwell’s picture

I have also tested this behavior with https://www.drupal.org/project/multiple_fields_remove_button and it's the same thing. Not surprisingly, the code is almost the exact same as well.

For now I need to move on. In the hopes that it will help someone either A) get closer to fixing the issue or B) improve the experience for users until it can be fixed, I'm attaching a patch that I am using for the time being. I would recommend replacing $element['actions']['remove_button']['#submit'] with a callback to your modified function.

First, it just adds #states to hide the remove button if an element doesn't have a selection (specific to my use case but it can easily be adapted). Second, it resets the value of the element (I'm only dealing with one subfield right now so I'll have to adjust it as more are added) if a user tried to remove it.

Sorry this isn't much help :(

elijah lynn’s picture

Somewhat of the same issue but maybe worth making another for is that if you don't choose unlimited and choose a fixed amount. You have to remove or reset all the fields manually if you want to 'remove' one.

chrisrockwell’s picture

Hi Elijah, I wasn't able to reproduce that on a simplytest.me install using 7.x-1.0-alpha4. I created a field with cardinality of 3 and then went back and edited the node 3 times, removing one entry at a time.

I did have to clear out the field to remove it, which isn't user friendly but isn't an issue isolated to this module. I do think it would be a UX improvement to have "Add Another" and "Remove" to add fields as needed, up to the set limit, instead of just having it on unlimited value fields.

This issue came up in a demo today so, maybe, I'll be given some time to look further into this :).

elijah lynn’s picture

Yes, that is what I was referring to. It would be nice to have a 'reset' button in that case.

dave reid’s picture

Yeah, it's a problem not unique to multifield itself, but to all field widgets.

elijah lynn’s picture

@Dave Reid - Thanks for clarifying that. I did go ahead and make an issue for a remove button in Multifield, any suggestions are appreciated as I have to get this working.

#2751755: Create a 'remove/reset' button when not using 'unlimited' value for field instance

elijah lynn’s picture

I have been investigating #2782747: Removing Multifield followed by 'add another item' adds back the removed item and there are a few issues for Field Collection linked to that one. When those patches are refactored into Multifield it appears this issue may also be resolved. As the latest Field Collection removes/resets the last entry correctly.