Hi,

Is there a standard or built in way to handle removing fields that can
have multiple values? E.g. when
admin/structure/types/manage/my_content_type/fields/my_field >
MY_Field field settings > Number of values is greater than one.

Forms that allow multiple value fields automatically put an "Add
another item" button at the bottom of the list of a multi-value field.
Is there some way to get a remove button for each item?

Comments

nevets’s picture

For the ones without a remove button you typically remove/unset the value.

LarsKramer’s picture

Having to empty the field and then save the node in order to remove the field is not intuitive to end users. Especially if the field has subfields.

Do you know of any field types or modules implementing a remove/delete button?

LarsKramer’s picture

Quick Tabs for Drupal 7 has a nice implementation of a remove button on the configuration page.

afeijo’s picture

I'm after this too, I added an remove link with jQuery, it removes nicely (visually), but if the user click the Add new value button, the removed value returns lol
we need to use ajax to update some cache, not sure yet...

huge hug
Feijó

emergencyofstate’s picture

I'm trying to find a solution for this as well. I have a custom module with a compound field containing multiple fields. When I add this field to a content type and set the value to 'unlimited' I get an "Add Another" Item button on the node creation form but no Remove button. Any ideas?

djahjah’s picture

subscribe

vivefree’s picture

subscribe

clock’s picture

subscribe

emergencyofstate’s picture

Although this has to do with the Field Collection module, it's another reference to what I believe is the same issue:

http://drupal.org/node/1222608

daggerhart’s picture

After hitting this problem, I wrote a simple hack-module for adding remove buttons to unlimited fields.
It has a configuration page where you can enable the remove button for any unlimited fields in your system.

You can download it here.
http://websmiths.co/blog/drupal-7-unlimited-fields-remove-button

The javascript takes a very brute force approach to clearing the input values in that table row. I would appreciate any thoughts, opinions, or suggestions for this.

With a little more work I think this could become a legitimate contrib module.

Thanks.

edit: updated the link to go to the blog post where module is available. I've been doing updates and this is easier than finding all my forum posts to update.

tinto’s picture

daggerhart, thanks for the great code. I managed to get it working in one out of three Drupal 7 installs and I have no idea why two are not working - the button simply does not appear. If you need any debugging info, please let me know.

Anyhow, I really think you should consider developing this into a module. It's offers awesome functionality!

daggerhart’s picture

Tinto, thanks for the encouragement.

Could you describe the two situations where it is not working, and I'll give it a troubleshot.

The types of fields you're applying them to, how those fields are setup (widget type, number of values allowed), and the admin theme being used.

I'll apply for a module repo today.

tinto’s picture

daggerhart, I think my colleague managed to figure out why we didn't get it working in some of our installs. He'll post his findings in your project's issue queue (http://drupal.org/project/issues/1363702) later today.

Should be interesting! :)

jibran’s picture

Somehow module was not working and I replace line 2 in unlimitedfield_remove.js from
jQuery('div.form-wrapper').delegate('.unlimitedfield_remove_button', 'click', function(){
to
jQuery('.unlimitedfield_remove_button').click( function(){
and it is working.
thanks nice module saved my a lot of time :).

daggerhart’s picture

jibran,

Thanks for the report. I believe the issue is that .form-wrapper div isn't being found on your site. The delegate function is necessary in my testing because after you 'Add new item', the existing remove buttons lose their click binding. I can take a better look at the issue this evening.

I have created a sandbox project for this module here:
http://drupal.org/sandbox/daggerhart/1363702

If anyone runs into problems in the future concerning this module, please post in the project's issue queue.

Thanks!
- Jonathan

danisha’s picture

come on daggerhart.. there are a lot of people around the world who are working on drupal 6. I havent found a solution for this on drupal 6. Your code looks awesome but can be please modify it a little bit for drupal 6 version please...

muthukrishnanr’s picture

Hi,

I used your module to remove the field from Unlimited Fields.

when i remove, its working fine.

But when i again clicked Add More Item, new fields are generating along with removed fields.

Let me know your suggestion on this

FranciscoLuz’s picture

I've written this module here http://drupal.org/sandbox/drupalista-br/1472442 which removes the field items via ajax callback.

It might solve this issue.

Please check it out.

Drupal in the Amazon Jungle

tanitani’s picture

There is no follow button on comments like this?

BG

cleancodenz’s picture

Recently I have done a blog about remove button for multi values field
http://www.cleancode.co.nz/blog/1131/multi-values-field-development-drupal

herderwu’s picture

jpschroeder’s picture

Needed a way to do this for my custom compound field. This module got me going in a matter of minutes!

https://www.drupal.org/project/multiple_fields_remove_button