Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I was trying to remove a link from a node and found that I couldn't. Even when I deleted the link text it gave me an error saying I needed to enter something in the URL field. Would it be possible to add a remove button to the edit screen once a link has been added? Something similar to the file upload field?
Comment | File | Size | Author |
---|---|---|---|
#16 | add-remove-button-905492-16.patch | 6.9 KB | junaidpv |
#12 | needs-work.patch | 4.76 KB | dsdeiz |
Comments
Comment #1
jcfiala CreditAttribution: jcfiala commentedNo, probably not. It's only complaining about needing to enter something in the URL field because of the settings on the field - one of these is probably true:
1) You've got the field on that node type set to required.
2) You've set the field up so that it requires a url if there's a title, and you didn't blank out the title also.
I suspect #1 is the correct answer. If you stop the field from being required, you'll be fine.
Comment #2
bmango CreditAttribution: bmango commentedThanks very much for the reply. I thought it was strange that I couldn't remove it. I'll try your suggestions. Thanks again.
Comment #3
kennywyland CreditAttribution: kennywyland commentedPlease don't dismiss this request. I would like the Remove button as well. I don't have my Link field set to Required, but if I've got 5 urls in a Link field, I have no way to delete them.
Emptying out all 5 of those values doesn't remove the values, it just makes the field have 5 empty values. That means the node behaves as if it has 5 Link values instead of 0.
Kenny
Comment #4
mrfelton CreditAttribution: mrfelton commentedI think this is a valid feature request. It would be a big + for usability. Bumping to 7.x
Comment #5
jenlamptonI would also like a remove button, for the reason specified in #3.
I've stumbled across three different modules that are all trying to solve this UI deficiency for fields in general:
* the multiple_fields_remove_button module
* the cck_multiple_field_remove module
* the field_remove_item
Maybe one of these will help someone else who finds this issue.
Comment #6
dsdeiz CreditAttribution: dsdeiz commentedEmptying the field works as expected now. I don't think a "Remove" button is still necessary.
Comment #7
heylookalive CreditAttribution: heylookalive commentedIn addition to the comments in post 3, I consider this a UX fail as a remove button per item makes it clear as to how to remove an item. Blanking fields out is obscure and not intuitive.
Comment #8
jcfiala CreditAttribution: jcfiala commentedWell, what field modules do provide a blanking button?
"Blanking fields out is obscure and not intuitive."
It seems to be the way that fields are constructed in core, and I tend to be willing to follow them as an example. That being said, I'd be willing to review a patch if someone wants to create one.
How is this issue handled in Drupal 8, by the way?
Comment #9
MrPaulDriver CreditAttribution: MrPaulDriver commentedFile - for one.
Ordinary folk don't get it, that they have to blank out the text. A remove button is very necessary.
Comment #10
heylookalive CreditAttribution: heylookalive commented@jcfiala Core does many things :) I can't say that this is a priority for me in terms of patching, but will help however else I can (reviewing or whatever).
Comment #11
dsdeiz CreditAttribution: dsdeiz commentedI'll try my hands on this. I took a look at the options from the existing modules posted at #5.
multiple_fields_remove_button
provides a really good UX since it adds a 'Remove' button on each item in the form. I'll try to borrow some code there and see if I can get it to work.Comment #12
dsdeiz CreditAttribution: dsdeiz commentedHi,
So I gave this a try. I used exactly the same code as from the multiple_fields_remove_button module (literally copied) specifically from here. I'm not entirely sure how this should be handled i.e. taking code from another module. I also tried removing some parts of it though it looks like it works exactly with the same code.
I haven't finished it but I think I'm close. There's something that's blocking me though. My AJAX callback is this:
$form[$key]['#id']
becomes#edit-field-name--1
since I think the form has already been processed and having the id already existing for#edit-field-name
thus not being able to replace the correct element. Changing$form[$key]['#id']
with something like#edit-field-name
works although it only works the first time you replace the whole widget.I've attached the patch for anyone who can help me out.
Comment #13
dawehnerInstead of using this patch I went with https://drupal.org/project/field_remove_item which worked perfectly
Comment #14
dsdeiz CreditAttribution: dsdeiz commentedYeah actually wondering if this is still necessary because the modules suggested above improves the UX although the current functionality which is to simply to empty the fields in the 'container' follows core. Also the patch I tried to work on (but failed miserably) completely copies the codes from the suggested modules.
Comment #15
silvi.addweb CreditAttribution: silvi.addweb at AddWeb Solution Pvt. Ltd. commented@bmango,
Use https://drupal.org/project/field_remove_item
and apply patch from following links: https://www.drupal.org/node/2491939
Hope this works perfectly for you now.
Let me know in case of any query/concern.
Thanks!
Comment #16
junaidpvWorking patch is here. Tested and working good for me.