When adding nodes that have commas or double quotes in the title, the entity connect field gets confused and cannot locate a node that doesn't exist. For example:

  1. I am trying to connect a document node called "Agenda - January 30th, 2014"
  2. I open my Event content type, in the referenced field, start typing "agenda…" and the autocomplete field finds "Agenda - January 30th, 2014", I select it.
  3. When I save the event content type I get this message

There are no entities matching "Agenda - January 30th"

This will not happen if the there is only one entity referenced with a comma in the title and its the last one added. Otherwise if there are two are more added it will throw this error.

This also happens with entities that have double quotes in the title, for example '12" vinyl'.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

CMStom’s picture

I've just noticed that Entity connect adds double quotes around titles that have commas, as it should. However, when adding a second entity with a comma in the title, the field will remove the double quotes from the previously selected entity.

To work around this one must make sure to add double quotes around these titles manually before saving.

jygastaud’s picture

Project: Entity connect » Entity reference

Hi @thoughmas,

Just try your issue without entityconect and I'm able to reproduce it.
I think it's more a bug on Entity Reference Autocomplete widget itself so I'm moving the issue into Entity Reference project.

iancawthorne’s picture

I am also getting this issue with entity reference on it's own.

CMStom’s picture

jygastaud, thanks for moving the ticket.

iancawthorne, Thanks for confirming!

I do still need this fixed. I wonder if entity reference can use a different delimiter other than a comma. I haven't' dug into the code yet but it's on my list of todos.

iancawthorne’s picture

The issue I'm experiencing is that the first referenced item gets double quotes round it, then when the second reference is added, the quotes get removed.

If the referenced title is surrounded by double quotes, it works. So, you can add the quotes in manually.

The issue is still there though.

akleinwaechter’s picture

It seems that somewhere in the javascript the quotes are removed for the prior entries when a new one is added. I can't find the place. I have names in the node titles like name, given name. So I go crazy. select lists are not really an option with 10.000+ entries :-(

Help would be appreciated.

Cheers
Alex

bendiy’s picture

Title: Cannot add referenced nodes that have commas in title. Field widget autocomplete (tag style) » Cannot add referenced entities that have commas in title. Field widget autocomplete (tag style)
Status: Active » Needs review
FileSize
1.44 KB

I've run into this issue and have tracked it down to jQuery.form.js and Drupal's ajax.js. This happens to me on non-tag entityrefrence_autocomplete field types, but only when the form is a "multipart" form. The reason this is happening is because of these lines:
http://drupalcode.org/project/drupal.git/blob/dc791ec5839b52c7616bf66993...

// The triggering element is about to be disabled (see below), but if it
// contains a value (e.g., a checkbox, textfield, select, etc.), ensure that
// value is included in the submission. As per above, submissions that use
// $.ajax() are already serialized prior to the element being disabled, so
// this is only needed for IFRAME submissions.
var v = $.fieldValue(this.element);
if (v !== null) {
  options.extraData[this.element.name] = v;
}

When a comma is in the entity Title, "v" above can have a value like this :

v === '"1600 Pennsylvania Ave NW, Washington, DC (1600)"';

http://drupalcode.org/project/jquery_update.git/blob/baff5d15a438cfa8216...

    if (options.iframe !== false && (fileInputs || options.iframe || multipart)) {
            // hack to fix Safari hang (thanks to Tim Molendijk for this)
            // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
            if (options.closeKeepAlive) {
                    $.get(options.closeKeepAlive, fileUpload);
                 }
            else {
                    fileUpload();
                 }
    }
    else {
                 $.ajax(options);
    }

The fileUpload() function will be called for multipart forms instead of $.ajax(options) which does not cause this issue.

http://drupalcode.org/project/jquery_update.git/blob/baff5d15a438cfa8216...

                         // add "extra" data to form if provided in options
                         var extraInputs = [];
                         try {
                                 if (s.extraData) {
                                         for (var n in s.extraData) {
                                                 extraInputs.push(
                                                         $('<input type="hidden" name="'+n+'" value="'+s.extraData[n]+'" />')
                                                                 .appendTo(form)[0]);
                                         }
                                 }

                                 // add iframe to doc and submit the form
                                 $io.appendTo('body');
                 io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
                                 form.submit();
                         }

This will generate a hidden input form field like this:

<input type="hidden" (1600)""="" DC="" Washington,="" NW="" Ave="" Pennsylvania ="" 1600="" value="" name="field_entityref_test[und][form][entity_id][target_id]">

Note that the value is empty. When this form is POSTed, the $_POST value for the target_id will be empty and no reference will be created.

This issues is caused by using double quotes around an entity title when there's a comma in it. If we use single quotes instead, the issue goes away.

See the attached patch.

Status: Needs review » Needs work
CMStom’s picture

bendiy,

I applied the patch to entityrefence.module file, here's my experience:

I'm using the autocomplete tag widget. In my use case I have an event content type that has referenced document content types. When I search for documents in the reference field, now single quotes appear. This is fine by me, great. Also when I add in a second document the previously added document still has single quotes -- this is great also.

The problem I ran into was when i tried to save the event, I got a form error message at the top that says

There are no entities matching "'document"

"Document" was the first part of the title before the comma. I can't save the event.

I'm going to revert the patch for now. Thank you for the time and notes you posted, very helpful. If you get around to another solution I'll be happy to test it out for you.

best,
Thomas

bendiy’s picture

@thoughmas

Sorry about that. Try this patch, it should work.

Status: Needs review » Needs work
bendiy’s picture

I'm not sure why SimpleTest can't seem to apply this patch. Trying again.

Status: Needs review » Needs work
bendiy’s picture

Status: Needs work » Needs review
CMStom’s picture

I think its failing testing because in your patch you are changing it from single quotes back to double, but in the original module code it's already double quotes. Did you want to stick with the single quotes like in your first patch?

bendiy’s picture

SimpleTest fails because it can't apply the patch with git. I can apply the patch just fine here.

It should stay with single quotes. That fixes the ajax submit issue.

The switch back to double quotes in _entityreference_autocomplete_tags_validate() is to get drupal_explode_tags($tags) to work correctly. It expects double quotes around strings with commas and will split them up correctly.

CMStom’s picture

Actually, scratch what I said prior. I am now able to save the event without the error

There are no entities matching "'document"

It remembers previously selected single quotes too.

Now the only issue I have is when you add new documents from the green plus sign next to the reference field. The single quotes won't add around content added via that method. This green plus sign is provided by the entity connect module, a permission setting must be enabled to see the green plus, "Allows users to see add button"

pfrenssen’s picture

Title: Cannot add referenced entities that have commas in title. Field widget autocomplete (tag style) » Cannot add referenced entities that have commas or double quotes in title. Field widget autocomplete (tag style)
Issue summary: View changes

This problem also occurs with entities that have double quotes in their title, such as '12" vinyl'. I'm afraid that a solution that replaces quotes will not be sufficient to solve this case as well.

bendiy’s picture

Status: Needs review » Needs work

@pfrenssen
I thought this might happen.

I think the root cause of the problem here is pushing the target_id number into the autocomplete search field. There is no telling what will be in the title of a related entity. The current approach is just not fixable.

I propose that the entityreference auto complete field move this target_id number to a second, separate, hidden field. When you do an autocomplete search, the entity title is returned along with this second field. Some javascript code would then parse the response and put the title into the search text field and the target_id into the hidden field. The form submit handler would then pull the target_id from the hidden field. No need to parse the title to find the target_id.

drupalok’s picture

any news on this? would be nice to use the module... but i can't loose my commas

Status: Needs review » Needs work
AdamB’s picture

I'm seeing this same problem using version 7.x-1.1.

othermachines’s picture

This patch in #12 seems to resolve commas, but quotes are still problematic.

When a second selection is added, Dwayne "The Rock" (1) changes to Dwayne.

In my testing, the simple fix over at #2576749: Autocomplete multivalue coma fix resolves both commas and quotes. The terms are added successfully on save, although the display is not necessarily ideal:

"apple ""banana"" (1)", orange (2)

Not sure how important that is.