Needs work
Project:
Drupal core
Version:
main
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Mar 2016 at 16:15 UTC
Updated:
16 Aug 2026 at 22:37 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kevin.dutra commentedI'm going to leave this at normal priority for the time being. A case could be made for data loss, since it's dropping the other values without any warning, but I don't think that this form element is really being used on it's own much in core. I'll happily defer to someone else if they think priority should be higher.
Comment #9
oknateOur QA team reported this bug. I've attached a video I created using the EntityReferenceAutocompleteWidgetTest.php using Drupal 8.8 alpha.
This is still an issue. There should be some sort of javascript preventing more than the allowed cardinality from being entered. Or perhaps validation on the backend that returns an error. Nothing terrible happens, but it allows you do something odd.
Comment #10
danielvezaAssigning to myself to have a dig in over the upcoming weekend. If others want to jump ahead feel free.
Comment #11
danielvezaEDIT - Ah sorry ignore this patch - Had a bunch of local changes I was playing with for a talk.
Comment #12
danielvezaLooking at the code it looks like this is desired behaviour - But I think I agree that it should fail validation instead of just grab the last value. Thats too confusing for editors IMO.
I think we need a test for this too if everyone agrees it should work this way.
Comment #13
larowlanI think this should use
\Drupal\Component\Utility\Tags::explodeinstead of just regular explodewe can return here and avoid the else to reduce complexity
I agree - this sounds like a genuine bug - we should be able to reproduce it in a test
Comment #14
krzysztof domańskiComment #15
glenndw commentedI have edit the patch. When you have references for autocomplete that contain a comma (like node title) previous patch will not allow it.
When Drupal detects a comma in a reference it will put quotes around the hole thing. So now we have a regex that will see if a comma is in the value that is outside of quotes.
Example
This wil be oké
value -> "title part1,2,3 (node_ID)"
This is not
value -> "title part1,2,3 (node_ID)", "title part 4,5,6 (node_ID)"
In previous patch
value -> "title part1,2,3 (node_ID)" Trows Error message
Comment #16
hardik_patel_12 commentedReapplying patch.
Comment #17
hardik_patel_12 commentedComment #18
Lal_why are we commenting this ?
Comment #19
Lal_Comment #20
neslee canil pintoComment #22
karthikeyan-manivasagam commentedHi,
Thank you all, after applying the patch, When trying to add multiple values in comma separated instead of showing validation error it throws fatal error, on Drupal core 8.9.20
InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\Database\Connection->expandArguments() (line 744 of /Applications/MAMP/htdocs/core/lib/Drupal/Core/Database/Connection.php)Thanks
Karthikeyan
Comment #23
karthikeyan-manivasagam commentedComment #26
naveenvalechaHere's the patch for 9.3.0
Comment #27
danflanagan8This is an interesting issue because, as pointed out in #12, the code spells out this behavior:
The patches above address item #2 in the IS, which might not even be classified as a bug since it is the behavior specified in code. I think we all agree the current situation is bad UX though. But if we add this validation though we clearly must update the comment too.
I also think that the regex in #26 should be removed in favor of calling
Tags::explodeand then callingcounton the result. We might as well re-use the existing code that does this.As far as item #1 in the IS, there's nothing in any of the patches that addresses that. That would probably involve some changes to the
core/drupal.autocompletelibrary.I would think that we could split those up into separate issues if we wanted. My guess is that messing with
core/drupal.autocompletecould get really nasty.Comment #29
liquidcms commentedJust tossing in my test results and comments:
- tested with core 9.2.16 and patch from #20 (#26 doesnt apply)
without patch:
- only the LAST item on the list is passed to my form submit handler
with patch:
- if i enter 2 items i get a form validation error
this is independent of setting #tags
IMHO, the proper functionality here is:
- if something is set on the form (#tags seems like an odd attr to define this), nothing should autocomplete past the 1st item - i think currently missing
- if user just enters values manually without aide of autocomplete; then validation error (as the patch does now)
- if single attr is not set; then all items should be passed to form submit - not working now
are these the goals here?
Comment #32
basvanderheijden commentedThe patch in #25 does not work because of a malformed RegEx. My patch uses Tags::explode instead.
Comment #34
sascha_meissner+1 Just stumbled into this ... IMHO it makes more sense to prevent completing multiple values client side in the first place. Just adding serverside validation is good but will just raise questionmarks in the opposite direction.
EDIT: looked a bit further and as the autocomplete js code will be replaced soon https://www.drupal.org/project/drupal/issues/3466088 my comment doesnt worth mention here
Comment #36
marckwee commentedHi,
I made a patch that is working with D11.
Comment #39
phthlaap commentedI added tests to reproduce the issue, and applied patch for it.
Comment #40
smustgrave commentedCould use a summary update to include the steps to rerpoduce