Problem/Motivation
I'm working on creating a custom field that has multiple entry items in the field. The field would look like this
Field 1 - Text
Field 2 - Text
Field 3 - Text
All would be saved into separate columns.
Now my question is with a cardinality of -1 the Add More works great to put the next item to enter but how would one item be removed from the list of them. Ideally a "delete" or "remove" button would be at the end of the item line but I don't see this. I know with a single field emptying the text field "removes" it but this isn't obvious to a use.
It's not unlike the Remove button that appears next to the Image Fields when multiples are allowed.
Is this something available or less of a support request and more of a feature request?
Note: For 7.x there is a contrib module for that: https://www.drupal.org/project/multiple_fields_remove_button
This issue is about adding that functionality to core.
Copied from #93447: Deleting the first value in a required, multivalue field fails validation
Proposed resolution
Use ajax and reload element to remove the item from the page.
Remaining tasks
- Decide on direction
- Add tests
- Review
- Commit
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#285 | Screenshot 2024-01-18 at 9.03.30 AM.png | 120.05 KB | nicole.harnish |
#285 | Screenshot 2024-01-18 at 9.03.17 AM.png | 124.62 KB | nicole.harnish |
#212 | 1038316-212.patch | 7.65 KB | Denisev |
#212 | interdiff_204-212.txt | 936 bytes | Denisev |
#214 | 1038316-214.patch | 8.43 KB | electrokate |
Issue fork drupal-1038316
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 11.x compare
- drupal-1038316/9.3.x changes, plain diff MR !2716 / changes, plain diff MR !2599
- drupal-1038316/11.x changes, plain diff MR !4319
Comments
Comment #1
yched CreditAttribution: yched commentedFeature request :-)
Comment #2
rogueturnip CreditAttribution: rogueturnip commentedThat's sort of what I figured but wanted to check :)
Similar request but for 6.x CCK
http://drupal.org/node/196421
The image really shows what would be ideal.
http://drupal.org/files/issues/cck-196421-71.remove-button-example.png
Comment #3
danielb CreditAttribution: danielb commentedI support this, I have two modules that appear buggy in some configurations because there is no way to remove one of the multiple values added with 'add another item'.
The modules are select_or_other and blockreference. I have given users, in addition to a regular multiselect box, the ability to create multiple drag-and-drop single select lists, which allows them to change the order of the selections.
However when set to 'required' and 'unlimited', there is #1117916: No way to remove added options.
The image shown in #2 by rogueturnip, showing a removal link on the right, is exactly what I've come here to request.
Comment #4
LarsKramer CreditAttribution: LarsKramer commentedNice idea. Moving to Drupal 8 where feature requests belong.
Attaching an image from Quick Tabs module which also has a remove button to the right of each instance.
Comment #5
rogueturnip CreditAttribution: rogueturnip commentedI like that this is being added to 8.x as a Feature Request but Drupal 7 is pretty early in it's life and ideally this would also appear there too.
I haven't tried this but I'm wondering if a kludge would be a button with javascript linked to it to empty the fields and then hide the row. Wouldn't degrade nicely but it's a thought.
Comment #6
afeijoI made that jQuery idea already, rogueturnip
but if you hit the add another value button, the deleted one returns :p
I will improve the jquery code to watch the button and delete the line again
Comment #7
tim.plunkettSubscribe. Linking to #196421-249: Deleting unwanted multiple values / multiple values delta issues for reference.
Comment #8
rogueturnip CreditAttribution: rogueturnip commentedWhat if instead of hiding the deleted row it instead greyed it out and changed the delete button to restore. This would allow for deleting rows and adding rows and then all the changes would be done on save. This way if you made a mistake on the delete you could restore it.
Any chance you could share what you've done with jquery so far?
Comment #9
tim.plunkett#8 is a second feature request on top of this one.
Comment #10
rogueturnip CreditAttribution: rogueturnip commentedI guess it would be. Maybe more of an enhancement to the initial feature request.
What I was looking for was if afeigo had any jquery code/module code he's written that he could share to get this feature in place without waiting for core changes.
Comment #11
rogueturnip CreditAttribution: rogueturnip commentedMaybe someone with more jquery and multivalue form understanding could tell me if this might work.
1. use js (through hook_form_alter?) to add a delete/restore button at the end of each element. use $form['#attached']?
2. if deleting, set disabled=disabled (grey it out), if restoring remove disabled
3. if deleting add a class of deleted
4. use hook_form_alter to add a new submit function that clears all the values for the elements with class=deleted
Because of my lack of deep understanding of mutlivalue elements I don't know if when a add item is clicked if any of this would even execute or if there would be some way to attach the action to the add item.
My guess is this might be able to be done in a contributed module for Drupal 7.
Comment #12
yched CreditAttribution: yched commentedThere was a similar debate for the CCK D6 multigroup feature.
What got implemented over there (done in parallel and independently of the D7 Field API work) was a "delete" button that let you "hide / fold" the corresponding row (or "unhide / unfold" it).
Comment #13
Fidelix CreditAttribution: Fidelix commentedSubscribing... This is much needed.
Comment #14
davidcie CreditAttribution: davidcie commentedSubscribing!
Comment #15
Refineo CreditAttribution: Refineo commentedsubscribing
Comment #16
MathRo CreditAttribution: MathRo commentedsub
Comment #17
jibize CreditAttribution: jibize commentedYes Sub!
Comment #18
charlie-s CreditAttribution: charlie-s commentedsub
Comment #19
odegard CreditAttribution: odegard commentedI've solved this in probably a very unsexy manner, but it works.
I've got a multiple field in a content type called TYPE. The field is called 'field_extrafield' and is a term reference field in my case.
Create a module called HOOK with this function:
This might not work out of the box. Mu case inparticular involves field collections so the arrays look different, but this should get you going.
This function add custom validation to the form after it is submitted. The first IF assures you you're working on the correct form. Then we're checking if a value has been set in the multiple field. The fields will be listed as numbered arrays under ['field_name']['und'], but there will also be string items here, so you need to check that you're working on items that are arrays (is_array). Since this is a term ref in my case, I'm checking to see if the array under ['und'] has the ['tid'] set. If not, I set the whole array to NULL using the form_set_value function. This is the only way to write changes to the form inside the validation function.
This feels like a very brutal way of doing it... setting fields to NULL in the validation form... any other suggestions?
Comment #20
rp7 CreditAttribution: rp7 commentedsubscribe
Comment #21
odegard CreditAttribution: odegard commented1) It would probably be better to unset the field rather than set it to NULL.
2) In views, you can rearrange the fields you've selected, but also delete them. MerlinofChaos has got this figured out. I suggest looking at his code for inspiration. I won't have time myself for a couple of weeks.
Comment #22
emergencyofstate CreditAttribution: emergencyofstate commented+1 for a Drupal 7 solution for this. Is #19 in the running? Anyone else use it successfully?
Comment #23
daggerhart CreditAttribution: daggerhart commentedDrupal 7 custom solution.
I just posted in another thread my custom module that can create a remove button for selected 'unlimited' fields in Drupal 7.
http://drupal.org/node/1143880#comment-5198566
Comment #24
jschrab CreditAttribution: jschrab commentedWill this work with image/file fields? Will the files get deleted or will there be dangling "fid's"?
Comment #25
daggerhart CreditAttribution: daggerhart commentedTo my knowledge image and file fields have their own Remove button in D7. I specifically added a configuration page to this module where you select which fields to apply the new Remove button in order to prevent complications with fields that already have this functionality.
I just tested Image and File fields on my D7 site, and they do already have a Remove button.
But to answer your question, no this module does not remove or delete any files or images. I've looked into how the File field removes fields using legitimate drupal ajax, and plan to contribute a module that does this correctly, but have not had the time to implement it yet.
Also, I found a tiny bug in the module and have fixed it. Everything should be working fine now.
Here is a link to my blog post where you can download the module:
http://websmiths.co/blog/drupal-7-unlimited-fields-remove-button
Any suggestions are appreciated.
edit: changed link to go to blog post, so I don't have to find all these links and change them after every update.
Comment #26
JordanMagnuson CreditAttribution: JordanMagnuson commentedThanks for the custom module daggerhart!
Unfortunately it's not working for me :( . I have an unlimited node_reference field (references project), and it shows up on your module's admin page, but checking it doesn't change anything when I go to edit a node that uses that field... no remove item.
Comment #27
daggerhart CreditAttribution: daggerhart commentedHi davidlerin,
I've updated the module to work with date fields, node & user references. The link above now goes to the updated module, but here it is again in case there is some sort of trouble.
v0.3
http://websmiths.co/sites/default/files/projects/unlimitedfield_remove-7...
Comment #28
jschrab CreditAttribution: jschrab commentedIs this an issue anymore with merlinofchaos's patch?
http://drupal.org/node/1234574#comment-5232728
Comment #29
daggerhart CreditAttribution: daggerhart commentedIf I understand it correctly, his patch applies to the field collections module. This issue is about core functionality of a remove/delete button for any type of field. Am I mistaken in this?
Comment #30
dww@daggerhart: #29 is correct.
To that end, any chance you can put your D7 contrib module here on drupal.org (even if it's just a sandbox project for now) so that discussion and support of your custom solution can continue in a more appropriate channel and we can leave this issue for solving this problem in D8 core?
Thanks!
-Derek
Comment #31
daggerhart CreditAttribution: daggerhart commented@dww,
Absolutely.
I have created the sandbox project for this functionality as a D7 module here:
http://drupal.org/sandbox/daggerhart/1363702
Sorry to hijack the thread.
Thanks,
- Jonathan
Comment #32
robcarr@daggerhart just downloaded your sandbox (version 7.x-0.3)
Thanks so much for posting this online and it's a great solution to an infuriating problem in D7. Should be in Core IMHO.
Thanks again - very grateful.
Rob
Comment #33
xjmTagging.
Comment #34
Albert Volkman CreditAttribution: Albert Volkman commentedJust checked out and used daggerhart's module. Worked perfectly. Thank you!
daggerhart++
Comment #35
bxCreative CreditAttribution: bxCreative commented@daggerhart - works perfectly!! Thanks for the save :)
Comment #36
druvision CreditAttribution: druvision commentedThe 'UnlimitedField Remove' module works great, but not for link fields. On link fields, the button doesn't appear at all.
Use-case: If the link field title is mandatory, I can't remove it at all (which is why I needed the 'remove' feature on the 1st place). By making the title optional, I can delete it in the usuall, non-intuitive D7 method, by simply deleting the text inside the field. But then I can't make it mandatory.
Ref: http://drupal.org/node/1616310
Comment #37
colinmcclure CreditAttribution: colinmcclure commented@daggerhart - works very well even inside field_collection with my custom multi-value field. There is just one niggle I found when testing it out...
If you have a field_collection set to cardinality -1 and you remove a field_collection container item with its Remove button then the remove button provided by module ceases to work until refresh.
Despite this little niggle and very specific use case, it works a treat and saved me a heap of time! Thank-you!
Comment #38
dremy CreditAttribution: dremy commentedHas anyone attempted this solution with Addressfield? Currently on node save, it adds the empty Addressfield and plots a point in the middle of the US in addition to the address submitted.
Comment #39
swentel CreditAttribution: swentel commentedMarked #1120162: Add "delete" links to multivalue field values as duplicate. Assigning to myself, going to try this during the weekend.
Comment #40
swentel CreditAttribution: swentel commentedOk, this is too crazy to get it right before 1 december.
Comment #41
Fidelix CreditAttribution: Fidelix commentedswentel, apparently there is more time to get this done:
http://buytaert.net/drupal-8-feature-freeze-extended
Comment #42
swentel CreditAttribution: swentel commentedYeah, but I'm not sure whether I have time enough for an initial patch before 1 december to get it going enough :)
Comment #43
jibranIs it still a feature request or can we convert it to task? It is very basic functionality missing form core so IMO we can change it to task.
Comment #44
jibranJust confirmed with @swentel on IRC he also thinks it is a difficult task.
Comment #45
swentel CreditAttribution: swentel commentedThis will be D9 material I'm afraid unless someone gets on this.
Comment #46
rafamd CreditAttribution: rafamd commentedWell .. given it's a normal priority task .. it wouldn't hurt in the 8.x queue for now?
FWIW, +1 to this fix, good day you all! :)
EDIT: oops, didn't mean to change version state, leaving it now, but please swentel or any other, adjust it as you see best.
Comment #47
Anonymous (not verified) CreditAttribution: Anonymous commentedI'd quite welcome this. In D7 I always had to create the remove button manually and this I think should be present in core.
Comment #48
Anonymous (not verified) CreditAttribution: Anonymous commentedBTW: additionaly I consider this quite important because if you have many values in a field and you manually remove the value, since there is no remove button, and you'll add another values you'll end up with empty fields and from UX POV it just looks bad.
Comment #49
Anonymous (not verified) CreditAttribution: Anonymous commentedSheesh 2 years and 11 months old issue.
Oh and I wanted to mention that this is a bit tricky only because fields are keyed by integers. If keys are changed to strings it's a piece of cake to programm the remove button functionality.
Comment #50
geerlingguy CreditAttribution: geerlingguy commentedSubscribing and adding that yes, this is a bit of a tricky problem to solve. There are few fields that implement a remove button (e.g. File/image fields and a few other custom fields), and it's hard (and annoying) to build in a 'Remove' button on custom multi-value fields, but it would be a huge UX win if we had this out of the box for multi-value fields.
I'm coming over from #2035753: Add 'remove item' function to multi-value autocomplete widget.
Note also that there's a contrib module that does what would be nice to do in core for multi-value fields: Multiple Fields Remove Button
Comment #51
paulwdru CreditAttribution: paulwdru commentedHowever, Multiple Fields Remove Button does NOT support all modules / widgets, each needs to be separately programmed.
Hopefully, Remove button is added to all multivalue fields in core for all modules / widgets
Comment #52
paulwdru CreditAttribution: paulwdru commentedHi,
I found a solution, with reference to #2287803: Make this work with all fields by default, apply Patch #4 on multiple_fields_remove_button-7.x-1.4.zip shall work with all modules and widgets.
Please take note that multiple_fields_remove_button-7.x-1.5.zip does NOT have the patch #4 committed, also not patchable with patch #4, already reported to the maintainer.
Drupal 8 shall make this in core coz it's ridiculous without a Remove button for Multivalue fields since day one.
Thanks
Comment #53
ArtusamakWill not happen in 8.0.x-dev since it's not critical.
Comment #54
paulwdru CreditAttribution: paulwdru commentedHi,
It's Absolutely Critical if your page has multivalue Field Collection, File, Image fields which already provided Remove button, the whole page will become Very Messy and NOT Standardized if some multivalue fields have Remove button while others do not.
Remove button shall be made in core so as to provide a user-friendly, clean and standardized interface. #2287803: Make this work with all fields by default
Thanks
Comment #55
jojonaloha CreditAttribution: jojonaloha at Metal Toad commented@paulwdru, I think @ARtusamak meant that it is not Critical based on the Priority levels of issues and because of that cannot go into 8.0.x since it does not qualify as an allowed change for patch releases. It looks like there is still a little time to get this in to 8.1.x, so a patch would be helpful.
Comment #56
jusfeel CreditAttribution: jusfeel commentedit's not working with editable display formatter so you won't clear the value through ajax save.
As always, great software needs a "working" UI or it's just for small group of geeks.
Comment #57
paulwdru CreditAttribution: paulwdru commented@jusfeel,
Drupal is always meant for Geeks, powerful & highly flexible, I love it.
The only drawbacks of Drupal are confusing / unorganized / inconsistent User-Interface, not nicely touched up in the perspective of end users' experiences.
Comment #58
geek-merlinAdded to summary:
Comment #59
Eyal ShalevI created a working remove item button in a custom field widget using the following code:
Comment #60
Eyal ShalevComment #61
geek-merlinCool! so needs-review...
Comment #63
mayurjadhav CreditAttribution: mayurjadhav commented@Eyal Shalev file is present but your patch didn't applied, let me try this patch.
If it gives the same result then i think bot Test has some issues, we need to work on them too.
Comment #64
geek-merlinThis would be easier to review if the (totally sensible) code style changes were not in it.
Comment #65
Eyal ShalevI tried to replace all the [] arrays to array(). This was done manually so it could fail.
Comment #67
mayurjadhav CreditAttribution: mayurjadhav commentedMarking as Needs Review for #63 patch.
Comment #68
geek-merlinCode looks good, but seems to need a rebase.
Comment #69
mayurjadhav CreditAttribution: mayurjadhav commentedI could apply the patch, so no reroll/rebase is needed.
Comment #70
geek-merlinSee the testbot in #65:
Comment #71
mayurjadhav CreditAttribution: mayurjadhav commented@alex.rutz, Yes #65 patch failed to apply and bot test too. I was talking about #63.
Comment #72
Eyal ShalevI've found some bugs with the first patch.
The changes are:
Comment #74
Eyal ShalevComment #76
Eyal ShalevSame as #74. I didn't patch against 8.1.x
Comment #77
szato CreditAttribution: szato at Brainsum for Tieto commentedTested, works for me.
One comment:
Removing the last item removes the "Add another item" button too (because the whole wrapper is re-generated by ajax with no item).
My solution:
added checking:
$field_state['items_count'] > 0
to avoid deletion (displaying the remove button) when only one item is left.
Comment #79
szato CreditAttribution: szato at Brainsum commentedRe-test passed.
Comment #80
dropdiver CreditAttribution: dropdiver commentedThis is not working in autocomplete term fields, i get an ajax-http Error!
Comment #81
apraturu CreditAttribution: apraturu commentedI am having an issue related to removing single items from a list on an edit form, both before and after installing patch #77. I'm wondering if anyone has had a similar issue. It happens when I do the following:
1) Create a list of 3 items (A, B, and C) and save the list.
2) Open the list for editing. As expected, the list appears on the edit form like this:
1. A
2. B
3. C
4.
3) Remove item A and then item B. The list now appears like this, as it should:
1. C
2.
4) Click the button to add another item to the list.
The expected result is this list:
1. C
2.
3.
However, the actual result is this:
1. C
2.
3. C
The new item comes pre-populated with the item that was in that slot at the start, rather than an additional empty slot as expected. Any ideas on the cause/or solution to this would be extremely helpful. Thanks!
Edit: You can reproduce this behavior on simplytest.me with a clean Drupal 8.1.8 install. Just add a new field to an article content type with unlimited values and follow the steps above and you'll see the same result.
Comment #82
bleen CreditAttribution: bleen at NBCUniversal commentedI figured out the cause of the issue in #81 though I have no idea what the correct fix might be... Here's the problem:
During the course of processing the form, the FormBuilder->rebuildForm() method is called. It, in turn, eventually calls a stack that looks like this:
If you take a close look at EntityFormDisplay->buildForm() you see this:
The problem is that
$items
gets set based on the cached$entity
object without taking into account the changes that have already been made to the form as reflected in$form_state.
A quick-and-hackey fix would be to let this happen and then after the fact, adjust
$items
based on$form_state
, but this seems both wasteful and fragile.I think this is a core bug regardless and should maybe (probably?) be addressed outside of this issue, but I'm not sure. A LOT of dominos have to fall in just the right way, but this could lead to an editor inadvertently overwriting his/her own data if their site has code to manipulate the entity edit form the way that the functionality in this issue would if it ever gets in.
Comment #83
dj1999 CreditAttribution: dj1999 at Brainsum for Tieto commented#77 patch working my fine except comment #80.
Regarding #80 prepare a patch. Please review it.
Comment #85
dj1999 CreditAttribution: dj1999 at Brainsum for Tieto commentedPatch again.
Comment #87
bleen CreditAttribution: bleen at NBCUniversal commentedHere testbot... Here boy
Comment #88
mpotter CreditAttribution: mpotter at Phase2 commentedOne problem with this patch is that the removeItemSubmit public function added by this patch is incompatible with the same function name used in the entity_browser module (entity_browser/src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php)
I suggest using a different name here so it doesn't break existing sites.
Or, if entity_browser needs to update it's argument list, let me know and I'll submit that as an issue for them, but wasn't sure they would care about a conflict with a patch that hasn't been committed yet.
Comment #89
bleen CreditAttribution: bleen at NBCUniversal commentedThe patch in #85 has some issues...
First, the "remove" button does nothing at all in the following circumstance:
Another issue (I'm 99% sure this is realted to #81/#82:
Comment #90
smiletrl CreditAttribution: smiletrl commentedI was working on this issue these days, and this is one widget working for my string text field. It uses some code from field_collection module, adds a few customization. Maybe someone can get some idea for your customization.
Comment #91
mpotter CreditAttribution: mpotter at Phase2 commentedsmiletrl: rather than pasting a huge amount of text like that, it would probably be better to upload it as an actual file.
bleen: I can confirm both of the issues you reported, so agree this needs more work.
Comment #93
tacituseu CreditAttribution: tacituseu commentedHow about something simpler ?
Adding column and a checkbox, that is used in
WidgetBase::extractFormValues()
to filter out unwanted values.The advantage is that it avoids AJAX callbacks, also you can change your mind and just un-check.
Could also add JS/behavior for it that hides the checkboxes and adds buttons in their place (that just toggle the hidden checkboxes).
Comment #95
tacituseu CreditAttribution: tacituseu commentedComment #96
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComments should (noramlly) begin with a capital letter and end with a full stop / period .
use short array syntax (new coding standard).
Comment #97
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #98
rgpublicHm. Don't know if I'm mistaken but patch #97 seems to add the checkbox to every field - no matter whether it actually consists of multiple values (cardinality!=1) or not.
Comment #99
tacituseu CreditAttribution: tacituseu commented@rgpublic: it is added inside
if ($is_multiple) {...}
right beside'_weight'
so it really shouldn'tComment #100
rgpublicAh, thanks @tacituseu. See it now. Did a mistake while adapting the patch to 8.2. It seems to work now. I've attached it in case anyone needs this.
Comment #102
tacituseu CreditAttribution: tacituseu commentedAdds class 'removed' to the row so it could be themed or just "display: none"d.
Comment #104
tacituseu CreditAttribution: tacituseu commentedComment #105
tacituseu CreditAttribution: tacituseu commentedMissed
.once()
in behavior, converted to button triggered to be consistent with field and image widgets.Comment #106
GRO CreditAttribution: GRO commentedRe-roll of patch from #105 for 8.2.x
Comment #107
bleen CreditAttribution: bleen at NBCUniversal commentedCan you please comment on whether the latest patch addresses #81/82 and #89
Comment #108
tacituseu CreditAttribution: tacituseu commented@bleen: yes the alternative approach solves all of them by not messing with
$form_state
over AJAX.Comment #109
bleen CreditAttribution: bleen at NBCUniversal commentedI had a chance to test the patch in #106 and I can confirm that it does address #81/#82 as well as #89.
In addition I was not able to find any other problems when testing with textfields that have unlimited cardinality.
thumbs up from me
Comment #110
swentel CreditAttribution: swentel as a volunteer commentedThe patch from 106 is hard to scan with the unrelated coding standards updates .. can we leave those out please. Also, we definitiely need for tests for this.
Comment #111
tacituseu CreditAttribution: tacituseu commentedAlso needs work for fields with fixed (>1) cardinality, and no-js graceful degradation.
Comment #112
GRO CreditAttribution: GRO at Realityloop commentedRe-rolled patch from #106, removed coding standards updates and added a check of field items to only apply the remove button when the field is not a new/blank field item.
Comment #113
tacituseu CreditAttribution: tacituseu commentedNo-js graceful degradation and coding standard fixes from #112, left out "apply the remove button when the field is not a new/blank field item" as it forces you to "Add another item" to be able to delete last one, it makes sense in file/image widgets due to their nature but not on generic fields in my opinion.
Still no tests,
Comment #114
tacituseu CreditAttribution: tacituseu commentedComment #115
tacituseu CreditAttribution: tacituseu commentedMinor CSS cleanup, swapping order of button and checkbox to get styles consistent with file/image widget.
Comment #116
tacituseu CreditAttribution: tacituseu commentedComment #117
vytch CreditAttribution: vytch at Deloitte Digital commentedAdding a fix to #112 to solve a double binding issue
Comment #119
vytch CreditAttribution: vytch at Deloitte Digital commentedFixing patch
Comment #120
andypostTest for last patch
Comment #122
tacituseu CreditAttribution: tacituseu commentedCould you please stop this nonsense of rolling for 8.3.x/8.2.x ?
It is just pointless noise, there is no way this gets into 8.3.x.
Comment #123
rgpublic@tacituseu: But you forget that this might be very helpful for people who currently cannot upgrade and need this.
Comment #124
tacituseu CreditAttribution: tacituseu commented@rgpublic: I didn't, frankly they shouldn't use it on production, it's a hard problem, the issue was created in 2011 and is slow enough even without it, the proposed approach doesn't even have blessing of the system maintainers yet.
What would be very helpful is tests ;) they would be useful even if approach changes.
Comment #125
samuel.seide CreditAttribution: samuel.seide at Mediacurrent for Group Nine Media, Inc. commentedI tested the 8.4.x patch on a vanilla install of drupal 8.4.x dev, with the paragraphs and field_group module installed. If you create a field group add a entity reference paragraphs inside the group and give that a default paragraph, you will end up with this error:
in the code, the error is originating from the code
$remove_element = $item['_remove'];
as the default paragraph doesn't have a value for $item['_remove'] and so it comes over as null.Here's how I had the paragraph setup in the content type:
Comment #126
tacituseu CreditAttribution: tacituseu commented@samuel.seide: Thanks for testing, it happens because the code assumes (wrongly) that each field extending
WidgetBase
and overwriting::formMultipleElements()
will callparent::formMultipleElements()
, but Paragraphs doesn't.I will post an updated patch in a couple of days.
I'm not familiar with Paragraphs, is your expectation it will somehow 'work' with it, or just not break ?
Comment #127
samuel.seide CreditAttribution: samuel.seide at Mediacurrent for Group Nine Media, Inc. commentedMy expectation is that the patch should have some checking in it so that if the $item['_remove'] is not available then it won't run that code. Basically the patch should be able to function without it throwing up notices when a default paragraph is being used.
Comment #128
MRPRAVIN CreditAttribution: MRPRAVIN as a volunteer and at Valuebound commentedAdding the patch for removing the single item in the multiple text field values.
It is working fine in 8.3.3 branch
Please review
Comment #129
tacituseu CreditAttribution: tacituseu commented@samuel.seide: Here it is, also updated for ES6.
Comment #130
tacituseu CreditAttribution: tacituseu commentedThere's still some JS double-click issue when used within Paragraphs.
Edit: Caused by nested
'.field-multiple-table'
tables.Comment #131
tacituseu CreditAttribution: tacituseu commentedShould be fixed now.
Comment #132
samuel.seide CreditAttribution: samuel.seide at Mediacurrent for Group Nine Media, Inc. commented@MRPRAVIN Your patch contains a custom module in it - modules/custom/rb_account_profile/rb_account_profile.module b/modules/custom/rb_account_profile/rb_account_profile.module so there's no way to test it...
Comment #133
samuel.seide CreditAttribution: samuel.seide at Mediacurrent for Group Nine Media, Inc. commentedHere is a patch that should work for 8.3.5. See 1038316-131-field-multiple-remove-item-alt.patch if you're running 8.4.x
Comment #135
MRPRAVIN CreditAttribution: MRPRAVIN as a volunteer and at Valuebound commented@ samuel.seide Thanks for pointing one. I have updated the patch file now. Please test and let us know. May be this patch will be helpful :)
Comment #136
MRPRAVIN CreditAttribution: MRPRAVIN as a volunteer and at Valuebound commentedHere i have attached the patch after @samuel.seide comments reviewed. Please test this patch. I think it will help to someone in Drupal World :) It's works fine in 8.3 Drupal version. Need suggestions also please review.
Comment #138
tacituseu CreditAttribution: tacituseu commentedBackport policy, also Automated patch testing.
Comment #139
MRPRAVIN CreditAttribution: MRPRAVIN as a volunteer and at Valuebound commented@here Can someone point out me please why patch gets failed? Based on suggestions i'll work on it.
Comment #140
bleen CreditAttribution: bleen at NBCUniversal commentedI'm not sure why the patch is failing to apply, however there was a coding standards change a few months ago (longer?) that says Drupal expects the "[" notation for arrays (see https://www.drupal.org/docs/develop/standards/coding-standards#array) so this change (which is where the patch fails) is not correct anyway and should be removed from the patch... the same is true of other array notation regressions throughout the patch.
I'd bet a dollar that if you reroll the patch without those coding style regressions that all would be well with the world
Comment #142
MRPRAVIN CreditAttribution: MRPRAVIN as a volunteer and at Valuebound commented@bleen, Thank you for point out me :) Notation for arrays are changed in coding standards. you are correct.
Comment #143
realitylooprerolled against 8.4.x for my own use
Comment #145
tacituseu CreditAttribution: tacituseu commentedRe-roll of #131 after #2898261: In jQuery 3, $('#') throws syntax errors
Comment #146
heddnThere seems to be two competing approaches contending in this issue. #143 is with ajax and #145 is with checkboxes. Can we get an IS update and proposed resolution? The issue description is fine, but I don't see what/how we want to fix this agreed upon yet. That makes it really hard to review and provide feedback on patches, because I don't know which is the preferred approach. I only read back through the last 75 or so comments for the past year, and there wasn't any real sense on what has been decided. Can we decide on that before throwing more patches against this thing?
Comment #147
heddnComment #148
tacituseu CreditAttribution: tacituseu commented@heddn: #85 is the last
comprehensive patch on the AJAX path, but as mentioned in #89 it has some problems.
There's a lot of noise - people learning how to make patches, incomplete solutions, re-rolls for obsolete versions, #143 is just a last of "works for my limited use-case" patches (only textfield - started in #128).
Comment #149
heddnSo, one issue with #143 is that it only supports text fields. And the approach won't scale very well to non-text fields. Meaning, what is built there won't shoehorn into any other field types. So... back to the drawing board?
Comment #150
heddnI spent a fair amount of time banging away at this today. I figured out one thing here close the end of the day... we won't be able to do this without a some changes to field widget base. The latest non JS patch in #143 was done entirely on the sub widget. That doesn't work if you have ajax refreshing in the field. Which I have on my custom field. I'll have to changes some things up in the widget base. Because that's where the item_count is getting calculated and used in formMultipleElements(). In the $max variable.
No patch, because I don't have any code. Just lots of time spent in xdebug trying to figure out this special edge case.
Comment #151
heddnHere's a patch (it doesn't work yet). It doesn't seem to be removing the items. But, its moderate progress as we now are moved up to the base class. So all field types will eventually get this functionality.
Comment #152
heddnHere's a new patch that seems to work in all cases for my address field. It hasn't been extensively tested, but at least it seems to be functional. Sorry about the interdiff; I don't think it is very readable.
Comment #153
heddnOK, this is a proper interdiff for 152.
Comment #155
heddnHere's what it looks like fully loaded with several values/locations:
I've added a generous number of example locations on the page. I can remove any one of them or add another one.
When the page first loads with no values/locations, it looks like the following:
One must click add to add the first value/location.
Comment #156
tacituseu CreditAttribution: tacituseu commentedComment #158
heddnBased on some feedback from @alexpott in slack, I've improved the button language to read, "Add item" or "Add another item" depending on if this is the initial item or not.
Also, flagging for usability review.
Comment #159
alexpottReviewing #152.
The wrapper is being used for more than adding more. It is also being used for removing.
This looks completely unnecessary.
Could do something like
'#value' => $delta > 0 ? t('Add another item') : t('Add item'),
Not adding an item by default makes required fields in the single widget form work really nicely.
I'd have this set to [] because clicking add more shouldn't validate the exist elements imo.
Comment #161
alexpottAlso thinking about this some more I thing the remove thing should be optional - or maybe a whole new WidgetBase so existing code and alters still work as expected.
Comment #162
alexpottI don't think we need
$form['#wrapper_id']
.Comment #163
BerdirI'm wondering in general why it uses a *unique* ID. ajax IDs actually shouldn't be unique because the ajax systems relies on theming being not. For example, it automatically prepends messages to the replaced element. That only works if the ID does not change after the initial replacement happened as otherwise the second ajax command won't be able to prepend before the old ID.
I changed the paragraphs widget recently to a non-unique ID in #2939718: Remove validation of closed paragraphs, fix validation and display of validation message for collapse and it worked fine. Probably the only exception to that would be if you'd have multiple entity forms on the same page but I don't think that is supported, at least not for the same entity type.
I guess it doesn't matter that much for core as both add and remove ignore validation errors and are not expected to have any messages.
Comment #164
alexpottIf we move the wrapper ID creation to before the loop where we create each single item form we could put this in there and do less looping.
Comment #165
tacituseu CreditAttribution: tacituseu commentedAnd from that I guess... consensus has been reached, before another patch was thrown ? ;)
Comment #166
heddnre #165: not necessarily, but the use of form_state and #ajax does seem to be functional. And its a design paradigm that seems to resonate with a lot of Drupal users.
Ignore the patch in #158. It was overly ambitious. Here's a re-worked on top of #152 and addresses most of the feedback since then. The only thing I haven't touched is how to make it toggleable as suggested in #161.
Comment #168
idebr CreditAttribution: idebr at iO commentedRe #163
The id attribute must be unique in a document according to the html specifications:
https://www.w3.org/TR/html5/dom.html#element-attrdef-global-id
Comment #169
BerdirThat's not the point. I'm refering to the unique ID API which adds a random suffix.
Of course it has be unique client-side, but when the ajax update happens then we replace that ID with the new content, which then can have the same ID again, there is nothing wrong with that.
If you look at other #ajax, then they almost always even use custom #prefix/suffix with hardcoded markup, exactly to prevent that Drupal messes with those ID's in any way.
Comment #171
jan.stoecklerReroll & small tweaks; AJAX-callback should work now. Can't figure out how to generate an interdiff as patch file from #166 doesn't seem to apply.
Comment #173
jan.stoecklerAddresses/(hopefully) fixes some of the test failures.
Comment #175
cosmicdreams CreditAttribution: cosmicdreams commentedIs get_class($this) necessary? Or will $this suffice?
This seems like it might be cause of the test failures. Why -4?
Comment #176
jan.stoecklerI'm not sure, both seem to work, as well as
static::class
- don't have a preference & will implement whatever's most appropriate.As far as I can tell, we use -4 here to get "up" in the nested array from the triggered submit element to its field element to replace its previous state with it (the whole field element).
Comment #177
jan.stoecklerSomething that does not yet seem to work correctly: removing items after having changed their order (without saving in between) - this probably needs to be addressed.
Comment #178
tstoecklerRight, I would go with
static::class
, as well. As far as I know that always returns the same asget_class($this)
(although PHP being PHP after all, I wouldn't be surprised to learn that there are exceptions that that... ;-)).Regarding the suggestion to just use
$this
, i.e. to specify[$this, 'submitRemove']
as the callback: While that is a valid PHP callable and - in general - is actually the preferred way because it doesn't require the method in question to be static, it should not be used in the Form API / Render array context, because it is not serializable and Form/Render array may be serialized. That's why I think[static::class, 'submitRemove']
is the way to go.Comment #179
heddnChanged
get_class($this)
vsstatic::class
Comment #181
Peter Törnstrand CreditAttribution: Peter Törnstrand at Happiness commentedI have tested this patch with a content type, Address, with 3 different address fields:
Visiting address
Postal address
Delivery address
All fields can have multiple (unlimited) values.
I edit an existing Address with 1 value for each field.
I first delete the delivery address value.
I then delete the postal address value.
The postal address is deleted but is replaced with the data from the previously deleted delivery address.
The field label of field Postal address is also changed to Delivery address.
Drupal 8.5.6
Address 8.x-1.4
Patch from #179
See https://www.drupal.org/project/address/issues/2992810 for screenshots.
Comment #182
cchoe1 CreditAttribution: cchoe1 commentedHi Peter. I think I'm experiencing similar issues to yours. Is your address field inserted within some sort of wrapper for the form display? I.e. a paragraph reference, a container/fieldset/details/form group, etc, or anything like that? A site I tested this on is using the Link field within a nested paragraph and all the fields we wanted the 'Remove' button on was nested using a form group. I'm not sure what kinds of nesting might affect this but the Form Display for this specific paragraph type wraps all of our components within a 'field_content'. Thus the form displays within a container class on the front-end.
I think this wrapper was breaking the patch at Line 371. As such, I've made a slight correction to it which got it to work on my machine. It was looking for a value $user_input[$field_name] but it seems that it's not finding the value because it's not prefixing the form array with the correct keys. YMMV as I'm not entirely too sure what the actual underlying issue is.
Patch attached below.
Comment #183
cchoe1 CreditAttribution: cchoe1 commentedSorry, some debugging statements got left behind. Here is a cleaner patch:
Comment #184
progzy CreditAttribution: progzy commentedI've tested with patch #183 and got issue.
I've used Paragraphs module (latest stable version just like Drupal , 8.6.5, installed with composer)
I've created a custom content type.
I've created 1 paragraph with a single plain text field and a unlimited link field.
I've added this paragraph as a unlimited field to this content type.
Then created content from previous content type and add 2 instances of the paragraphs with 3 links for each. Saved.
Now on edition if I try to remove second link of first paragraph it is actually removed. Then I try to remove second link of second paragraph, nothing happens (except spinner) when I click "Remove" (Even if I can see an AJAX call in debugger). I click "remove" again and everything is messed up.
Some other combinations also lead to a messy result as well.
Comment #185
cchoe1 CreditAttribution: cchoe1 commented@progzy Thanks for the feedback.
I tried to recreate the same situation as yours. I added the text fields (limit 1) and links (unlimited) to the paragraph and then added the paragraph to a content type with unlimited cardinality. But when I hit 'Remove' on the 2nd paragraph instance, 2nd link, it successfully deleted it.
I'm going to try and recreate your bug on a fresh install but I thought I'd get back to you asap first. If you could, and if you think it's relevant, could you paste the 'Response' from the AJAX call that you see in the debugger?
Running D8.6.5, will try on 8.6.7 but I don't think there should be much of a difference. (Edit: oh I thought I saw you were on 8.6.7 but you're also on 8.6.5. Perhaps one of my custom modules is interfering so regardless, I'll try this patch on a fresh install and see what happens).
Comment #186
progzy CreditAttribution: progzy commented@cchoe1 you're welcome.
So I did it again. I did it at https://d0cq3.ply.st (admin/admin as user/pwd) so you can try by yourself (It only lasts 12h though). Any way here are the AJAX responses :
- First remove attempt that goes well: https://pastebin.com/raw/WyUbVTZX
- Second remove attempt that fails: https://pastebin.com/raw/THFdp2xS
Hope this helps.
Conf:
- Drupal 8.6.5 (not sure it your patch works with 8.6.7)
- Paragraphs 1.5
- Patch https://www.drupal.org/files/issues/2018-12-17/1038316-183.patch
Comment #187
cchoe1 CreditAttribution: cchoe1 commentedAwesome, thanks for setting that up @progzy, I did confirm it was still messing up with your test environment. Looks like when I try to delete l1.2, it replaces that reference with the second paragraph. But then if I try to delete something from l2.*, it brings back l1.*. I'll look into my patch and see if I can't figure out the problem.
Comment #188
cchoe1 CreditAttribution: cchoe1 commentedI've attached a patch below, I would not consider my changes to be good code but it makes a proof of concept and seems to work (solves the case above). I've attached a 'TODO: refactor' where we would want to come up with a more intuitive way of assigning a unique ID to the #name attribute.
Drupal Form API requires a '#name' attr on the form element to find the correct triggeringElement. Originally, there would be naming collisions when you have both:
- elements that have the same parent
- elements that are using the same field
When the form is being built, it attaches a delta to the name in an attempt to resolve this. This does not work in all cases--in this case, we are using 2 instances of the same paragraph type. It duplicates the names because deltas will be unique within the paragraph instance but not on the form itself, so two instances of identical paragraph types will result in fields with the same #name such as 'field_link_1_remove_button'.
Now, there should be no duplicated names on the form. Look for the '@TODO' tag (line 225). I'm not sure if this is the best way to name the Remove buttons or not.
To create the unique name, I simply implode the array_parents--no matter what element/field/grouping, this series of items in array_parents should be unique for any form element because it also keeps track of deltas across the entire render array--and then we also attach the local delta (it's position amongst its sibling elements) since that won't be present on array_parents.
Some reading I did:
https://drupal.stackexchange.com/questions/154387/why-does-triggering-el...
https://www.drupal.org/project/drupal/issues/2546700
Comment #190
phjouI just tested the patch and when I am using the remove button, it removes all the entities of the field instead of removing a specific element.
I'm using this patch with Inline Entity Form as described in this issue: UX issues with the Simple widget
Comment #191
rfbrandsma CreditAttribution: rfbrandsma commentedI can confirm the issue phjou addresses.
I would also like to report another issue with the patches so far:
The wrapper id for the add more button no longer is unique. In Drupal core the
Html::getUniqueId($id_prefix . '-add-more-wrapper');
is used to create a wrapper_id. The patches are using$wrapper_id = Html::cleanCssIdentifier($id_prefix . '-add-wrapper');
.Comment #192
rfbrandsma CreditAttribution: rfbrandsma commentedI can confirm the issue phjou addresses.
I would also like to report another issue with the patches so far:
The wrapper id for the add more button no longer is unique. In Drupal core the Html::getUniqueId($id_prefix . '-add-more-wrapper'); is used to create a wrapper_id. The patches are using $wrapper_id = Html::cleanCssIdentifier($id_prefix . '-add-wrapper');.
Comment #193
prudloff CreditAttribution: prudloff at Insite commentedI tried the patch in #188. When adding a value to a multivalued field, the AJAX request fails with this error :
Notice : Undefined index: #field_parents dans Drupal\Core\Field\WidgetBase->formMultipleElements() (ligne 227 de /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php)
Comment #194
SpadXIII CreditAttribution: SpadXIII at SIM commentedI added the getUniqueId-suggestion by rfbrandsma to the patch in #188. Other than this addition, the patch is identical to the #188 one.
While testing, I didn't see the notice prudloff mentions.I just saw the notice mentioned by prudloff. This was with a field that had no parents.Comment #195
SpadXIII CreditAttribution: SpadXIII at SIM commentedI noticed a little typo in the patch, so here's an updated version.
Comment #196
Tess BakkerThe Action type element, introduced in #128 conflicts with the Javascript implementation in Drupal.behaviors.dialog.prepareDialogButtons.
Buttons of multiple field values are now displayed in the button area of a dialog.
Screenshot:
Comment #197
bartzaalberg CreditAttribution: bartzaalberg at SIM commentedI've attached a new patch which seems to fix the previously noted issue. Hope this helps
Comment #198
bartzaalberg CreditAttribution: bartzaalberg at SIM commentedComment #203
sanfair CreditAttribution: sanfair commentedFix some tests and notices
Comment #204
sanfair CreditAttribution: sanfair commentedFixed for nested fields
Comment #205
semjuel CreditAttribution: semjuel commentedI wonder, why don't use Multiple fields remove button module - https://www.drupal.org/project/multiple_fields_remove_button ?
The module version for Drupal 8 works perfectly for me.
Comment #206
dww@semjuel: Because this is a task for Drupal core itself. We want the core system to be able to support this functionality, without relying on a contrib module.
Cheers,
-Derek
Comment #207
MrPaulDriver CreditAttribution: MrPaulDriver commented@semjue and @dww, yes this does need to be in core.
From screenshots in this issue it appears that efforts are being directed at a text based remove button.
The text button approach was originally used by Multiple Fields Remove Button module, but this has more recently been replaced with a simple delete icon. This works a lot better.
The same approach is also consistent with core ui as used in the media library module.
Please see screenshots
Comment #208
MrPaulDriver CreditAttribution: MrPaulDriver commentedComment #209
alexpottI'm upgrading this to a major task based on the usability and feel of adding an text field with unlimited cardinality to core. The result is very confusing because it is not at all apparent how to remove a value once you've added one. I'd go so far to say that the current behaviour is very surprising and not at all accessible.
Comment #211
Denisev CreditAttribution: Denisev commentedTried the patch from #204 for list items inside paragraphs. Having list item 1, 2, 3 and changing their order with dragging to 3, 2, 1 and then deleting the middle number 2, the order reverses after save back to 1, 3 instead of being the expected 3, 1.
Comment #212
Denisev CreditAttribution: Denisev commentedThis is a modified version of the patch in #204. The changes address the issue with loosing the order of items after save, when having removed items and also reordered them before. There are no new lines added, only a couple removed. Not sure, if this is the correct approach and if nothing else will break. So far it works in our environment.
Comment #213
electrokate CreditAttribution: electrokate commentedNeither #204 or #212 is working for me in Drupal 8.8.6. (#212 would not apply, so I made the changes manually to try it). Upon saving, it takes the last element in the $input array and assigns it a negative weight, such that it appears first in the list.
I am trying to fix this but could use some assistance! I can't seem to edit elements of the $input array in the submitRemove function. Perhaps the change needs to be made in the removeAjaxContentRefresh function?
EDITED TO ADD:
I have edited the code and it works for me now. I replaced the submit function as follows:
(Basically the "--key" needs to be inside the if statement that checks for the removed element, and the indices need to be reset afterward.)
Will follow up with patch.
Comment #214
electrokate CreditAttribution: electrokate commentedComment #215
DuneBLComment #217
andypostClosed as duplicate #2904621: removeItem() on multiple values field doesn't work
Comment #218
maximpodorov CreditAttribution: maximpodorov commentedWow. Both issues are closed now. Is this what you planned?
Oh. This one is not closed.
Comment #219
bobbygryzyngerIt looks like the behavior described in #3165908: Item removal AJAX causes infinite nesting is also occurring here since much of the behavior from the contrib module was ported over.
Comment #223
quietone CreditAttribution: quietone as a volunteer commentedClosed #93447: Deleting the first value in a required, multivalue field fails validation as a duplicate and adding credit.
Comment #224
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedRe-rolled #214 for 9.2.x. And also updated one of the failing tests.
Not able to generate the interdiff.
Here is the diff for the test.
Comment #225
fabianfiorotto CreditAttribution: fabianfiorotto commented#214 is working for me on 8.9.x but only for unlimited fields. I added a condition to hide the button when the amount of values is limited.
Comment #226
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedChanging to needs review so test bot can trigger pipelines.
Comment #227
mohit_aghera CreditAttribution: mohit_aghera at QED42 commentedComment #228
ankithashettyJust fixed the custom command failure errors in #225, thanks!
Comment #230
scott.whittaker CreditAttribution: scott.whittaker as a volunteer commentedThe patch in #228 works for me, except that in my case I have a field with unlimited cardinality and when I edit an existing piece of content which has n items, it only shows n-1 items.
In WidgetBase.php I needed to change the $max from $field_state['items_count'] - 1 to $field_state['items_count'] in order to fix this bug:
Comment #231
scott.whittaker CreditAttribution: scott.whittaker as a volunteer commentedComment #232
scott.whittaker CreditAttribution: scott.whittaker as a volunteer commentedPatch based on #228 to fix the unlimited cardinality bug.
Comment #233
Lal_Triggering the test bots
Comment #234
Lal_Rebasing #232 to the 9.1.5 version
Comment #235
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedFixed CS issue.
Comment #238
trishen CreditAttribution: trishen commentedDrupal 9.1.5
patch #235
Bug: pre-filled fields after deletion
Steps to reproduce:
1. Add an unlimited link field to node type
2. Create a node with multiple links
3. Save node
4. Edit node
5. Remove one item
6. Add another item
7. New item is already filled
Same behavior with module multiple_fields_remove_button
Comment #239
alphawebgroupWhy do we need that in core? Why not in cotrib module like we had in D7 ?
Comment #240
rp7 CreditAttribution: rp7 for Government of Flanders commented@alphawebgroup I believe #209 sums that up pretty well.
Comment #241
linhnm CreditAttribution: linhnm as a volunteer and commented#235 is working for me on 9.2.6 but only for unlimited fields. I added a condition to hide the button when the amount of values is limited.
Comment #242
neclimdulLove finding an issue so old there are people subscribing with comments...
I've cleaned some things, reverted some changes that seemed unrelated, and applied some earlier fixes that had been lost. Some of those lost fixes like clearing out the form array so config doesn't try to save the remove button should clear up some test failures.
I haven't really finished reviewing the submit handlers. The parent slicing makes me a little nervous because it seems kinda fiddly/brittle since its tied to the structure of the form. Skimming the thread that seems to be confusing other people as well. Submitting now because I wanted to see how this affected the rest of the test suite.
Also, clearly needs tests but that's tagged. Noting because its not really ready for review, just running testsuite.
Comment #244
maursilveira CreditAttribution: maursilveira at Northern Commerce commentedHello,
I tested the patch #242 and it works as expected.
Thank you!
Comment #245
DrDam CreditAttribution: DrDam commentedHi,
Test against 9.4.x and 9.5.x=> this work fine
Thanks
Comment #246
ordermind CreditAttribution: ordermind commentedFor me, if I click on the remove button when there is only one field value with data that has been saved to the database already, such as when editing an existing entity, the saved values are displayed again rather than empty values which is the expected behavior according to me.
Comment #247
ordermind CreditAttribution: ordermind commentedAnother bug I found was that if you delete a value as well as the empty "new value" item, and then click on the button to add another value, the value that you deleted will be displayed. According to me, the expected behavior is that it should be empty.
Comment #248
ordermind CreditAttribution: ordermind commented*** comment removed, this issue was due to code outside of this module ***
Comment #252
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedApplied patch #242 on 9.4.x.The
Remove
button appears which can be used to remove field items after applying this patch.Attaching screen recordings for reference.
Comment #256
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #257
brad.bulger CreditAttribution: brad.bulger commentedComing here from #93447 with a slight variation - this seems like a huge change to handle the problem.
Will this support a programmatic way to remove values from a multiple value field?
What I am seeing, in 9.5, is that if you have a required multiple value field, and you move the first item out of the first position on the form, it still retains its #required status, and still will fail with a required field error if blank, even though the "first" (from the user's perspective) element in the field has a value.
In my case, the user is not removing the value, my code is making the change. I need to be able to set an item's value to blank, whether it used to be the first item or not. The only workaround at the moment is to rebuild and resort all of the values, and even that is troublesome.
It seems like a bug in its own right that this fails, quite apart from adding a "remove" button as a new feature or whatever.
Comment #258
BerdirThis is solely a UI issue. If you want to remove an item from a field, you can use \Drupal\Core\TypedData\ListInterface::removeItem().
Comment #259
brad.bulger CreditAttribution: brad.bulger commentedNot from any hook functions that can modify a node form, for instance. The items list is not available, only arrays - user input, form state values, the form array.
Comment #260
solideogloria CreditAttribution: solideogloria commentedThis issue is specifically about making the user interface useable. If you have a problem doing something programmatically, you should create a separate issue.
Comment #262
perry.franken CreditAttribution: perry.franken at iO commentedWhen a site is multilingual the "Add another item" string is not translated. To fix this i created a patch that always uses the singular value.
Comment #263
perry.franken CreditAttribution: perry.franken at iO commentedIntern diff of patch 242 & 262
Comment #264
perry.franken CreditAttribution: perry.franken at iO commenteduse "Add another item" instead of "Add item"
Comment #265
perry.franken CreditAttribution: perry.franken at iO commentedThis time with patch.
Comment #266
lauriiiWe added the remove button inline with the input in #2521800: List key|label entry field is textarea, which doesn't give guidance towards the expected input. Could we do the same here?
Comment #269
vasikecreated a new MR for 11.x ... for anyone to join and "close" this ancient issue
- Started from the latest previous patch - #265
- Small refactor there
- Change
FormJSAddMoreTest.php
toMultipleValueWidgetTest.php
to test more things on multiple value widgets ... than just Add more button.And test remove buttons there.
On #266
I think it's already quite the same.
Comment #270
smustgrave CreditAttribution: smustgrave at Mobomo commentedSee tests have been added so think we can remove that tag
Leaving issue summary if there are anything that needs to be added
Testing by adding a text field
Set to unlimited
Added 3 items to the field
Verified they all get the Remove button
Removed the middle item
Everything saved correctly
But visually could use some tweaks.
Maybe could be done in a follow up but think it looks like a regression too much.
Comment #271
smustgrave CreditAttribution: smustgrave at Mobomo commentedoops actually get @lauriii requested the same in #266
Comment #272
vasikeabout UI
i think we have the follow up in the related issues ...
https://www.drupal.org/project/drupal/issues/3053449
where it seems there is plan for it ...
or there still something to be done here?
Comment #273
lauriiiI think all we need to do is move the remove button to its own column. We can handle rest of the styling in the follow-up. I pushed a commit which does this.
Comment #274
smustgrave CreditAttribution: smustgrave at Mobomo commentedWorks like a charm.
Comment #275
lauriiiThe test failure is due to broken HEAD.
Comment #278
lauriiiCommitted be46daf and pushed to 11.x. Thanks!
Comment #279
neclimdulExciting! This is something my users have been asking for for a long time! Is this something we'll see in D10?
Comment #280
mstrelan CreditAttribution: mstrelan at PreviousNext commented@neclimdul this will be in 10.2, see https://www.drupal.org/about/core/blog/new-drupal-core-branching-scheme-... for explanation of the 11.x branch
Comment #281
neclimdulright right.. that's still confusing.
Fixing my org credits.
Comment #283
mstrelan CreditAttribution: mstrelan at PreviousNext commentedOpened a follow-up bug #3376692: Removed values in multi-value fields reappear.
Comment #284
mahdeThis fix is causing an issue with nested paragraph as it show the "Order"
<td>
when there is no paragraph value is added.See the screenshot below:
When I removed the updated code in theme.inc file then it works fine.
Comment #285
nicole.harnish CreditAttribution: nicole.harnish at VERB Interactive commentedI am having the same issue as mahde.
Running Drupal 10.2.2
Debugging theme.inc it looks like there are 3 headers to 4 cells, causing an extra
Comment #286
lexsoft CreditAttribution: lexsoft at APMG International commentedCould someone please let me know how to disable this feature? From what I see, it does not have any UI control, and it's unreasonable to deploy something like this enabled.
Wouldn't the best practice be to deploy it disabled initially, with a checkbox on the field config to enable it? If we have multiple fields with, let's say, 5 entries already displayed, with data present but not visible to the user, giving them the ability to remove it could lead to serious issues.
Comment #287
solideogloria CreditAttribution: solideogloria commentedForm elements can already be disabled, using the disabled or readonly attributes. We don't need to add a config option for this.
Comment #288
solideogloria CreditAttribution: solideogloria commentedAlso, this issue is closed. If someone has a bug, it should probably be opened as a new issue in the queue.
Comment #289
bkosborneSurprised a change record wasn't added for this. Not that it's super disruptive, but admin theme maintainers may have wanted to know about this so they could see how the remove button affected styling of widgets. It also would have allowed me to discover this was a new feature in Drupal 10.2.
Comment #290
robpowellJust echoing some of the concerns raised here, having a CR would have been helpful to know about this change quicker. Having this off by default and configurable in the UI would be beneficial incase there are clashes with custom code or contrib like multiple_fields_remove_button.