Im using the module Entity reference 7.x-1.0-beta3 in a clean drupal 7.1 core.
And I have created an Entity Reference field in a content_type B with a autocomplete widget to list all the node's name of a content_type A.
The problem is the display is worked, but while I select a value from the autocomplete result list, it not only returns the node's name, but with an additional "(nid)" ex: "nodename1 (5)".
I'd appreciate if some one could help me.
Thank you!

Files: 
CommentFileSizeAuthor
#31 entityreference-autocomplete-1411304-31.patch4.11 KBakamustang
#11 entityreference-autocomplete-1411304-9.patch5.56 KBJvE
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreference-autocomplete-1411304-9_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Active» Closed (works as designed)

This is the standard behavior of entity reference. You need the ID number for it to function properly.

Ok, got it, I hope there could be a way to disable the way view in future. thank you for you answer :)

Category:bug» feature
Priority:Major» Normal
Status:Closed (works as designed)» Active

This may work as designed, but for normal users (visitors) this is confusing... Is it just not possible to code for the NID to be hidden or do you just not want to support this feature?

This module works perfectly the way I am looking to use it, but the NID showing is an issue for me...

Please let us know if you can at least consider this as a feature request or if we should look elsewhere for a solution.

Thank you.
PK

Title:Entity reference, it not only returns the node's name, but with an additional "(nid)" ex: "nodename1 (5)".Autocomplete widget should store reference id in hidden field instead of in autocomplete text field
Assigned:sunyu0072007» Unassigned

Feature request it is. I am not the maintainer of the module but I do have a project at my day job that needs this as well.

Here is how I have been thinking about tackling this:
1) append a hidden field to the end of the autocomplete widget field with a name like field_name_und_0_target_id_id or something like that.
2) update the autocomplete widget to strip out the parenthesis and insert the target id into the hidden field using jQuery.
3) get Entity Reference to look for the hidden field first and use that id as the value instead of the text field or if that value is blank let the normal process continue.

I think there is work going on at #1389238: Autocomplete widget improvements to help with some of the validation issues.

It should be noted that this issue is not intended to fix the validation issues or to automatically attempt to add entities if they do not exist. It is just a UI improvement for view the reference ids.

I appreciate it!

Even if just a temporary fix, this would be very welcomed! :-)

Let us know if you need any help testing.
-PK-

I'm looking for this as well

Status:Active» Closed (won't fix)

Entityreference is not in the business of providing new UI elements. There are alternative autocomplete implementations that you can probably leverage.

Status:Closed (won't fix)» Active

I see kind of a unique autocomplete situation with entity reference though. Feel free to close again if you disagree or if you know of an existing UI module that can handle this. The catch to entity reference is that we need a way of storing the entity id whereas a typical autocomplete does not rely on that. Several clients have complained about confusion with having the node id showing in the autocomplete field. They don't really care about the number but do care about the title. I think this whole process could be taken care of with javascript that converts the text field to a hidden field and adds a new autocomplete field that updates the hidden field automatically. The hidden field keeps the name of the original element and the value includes the node id in parenthesis so that gets validated the same. The new text field will strip out the parenthesis and node id for display. Maybe it has some sort of visual indicator as well when it has an exact match is being used with a node id.

Component:Code» User interface
Status:Active» Needs review
StatusFileSize
new5.56 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreference-autocomplete-1411304-9.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I have also had complaints from users being confused by the ids in parenthesis.
And the fact that in the autocomplete suggestion there is no distinction between entities with the same label.

My feeling is that this is best approached by treating the autocomplete like what it is: a textfield.
A textfield that offers suggestions on what to type when you have javascript enabled, but still a free-form textfield in which the user can enter anything they like.

What is needed for the entityreference usecase is an input element that allows a user to select a distinct option from a (potentially large) list of predefined options with potentially duplicate labels.

In the mean time there is attached patch.
It changes the display of the ids from (xx) to [id:xx] which seems to be far less confusing, especially for windows users.
It also displays the ID in the autocomplete suggestions so users are able to distinguish different entities with the same label. This also removes the dissonance caused by the box filling with something different from what the user clicked.
And finally it adds an option to the widget settings to remove the ids altogether. This should only be enabled when your entities have unique labels.

Status:Needs review» Needs work

The last submitted patch, entityreference-autocomplete-1411304-9.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new5.56 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreference-autocomplete-1411304-9_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

case sensitivity fail in patch :(

Status:Needs review» Closed (won't fix)

This is how the core autocomplete widget works everywhere. We are not doing anything special here. I'm open to the idea to have integration with a better autocomplete widget in Entity Reference, but let's not hack around with the core autocomplete.

Title:Autocomplete widget should store reference id in hidden field instead of in autocomplete text fieldAutocomplete widget entity id improvements
Status:Closed (won't fix)» Needs review

Sorry Damien, but I disagree.

The core autocomplete widget used everywhere equates the input with the value, which is something Entity Reference changes; it uses a value (entity id) different from the input (entity label).

This issue and patch is specifically about improving the usabilitly of this important difference that Entity Reference introduces.

Perhaps we should move the widgets from the Entity Reference module to a separate module?
Your thoughts?

Title:Autocomplete widget entity id improvementsAutocomplete widget improvements
Status:Needs review» Active

Please review alternative autocomplete libraries. As I said, I'm open to integrate with an alternative autocomplete implementation, but as far as core is going, this is what you get, and I'm not going to approve mucking with it.

I'm not sure we understand each other.

You are saying that I should fork the autocomplete functionality of Entity Reference into my own module if I want to see usability improvements on it?

Entityreference is not in the business of providing new UI elements. There are alternative autocomplete implementations that you can probably leverage.

1. Entityreference provides two autocomplete widgets.
2. The only other autocomplete functionality I can find that has value != input is in the References modules and that is poor compared to the Entity Reference implementation. I am not aware of any others.

The funny thing is that my patch actually brings the Entity Reference autocomplete closer to the drupal core autocomplete, so your comment confuses me.

I think hes talking about integrating into a project like this: http://drupal.org/project/autocomplete_deluxe

I'm including a lot more content in the autocomplete like full address information, but when you click on it, it puts everything into the input box. I'm trying to find a way to just include just the title... I don't care if the number is entered, I just don't want the address entered.

Status:Active» Needs review

I'd just like to say that this is an issue for clients I'm currently working with.
I'm looking at using the method described here:
http://stackoverflow.com/questions/1515722/removing-nidn-in-nodereferenc...

Just out of curiosity why a new project instead of implementing changes with http://drupal.org/project/chosen?

not the same thing

There is a duplicate: http://drupal.org/node/1802916

Issue summary:View changes

update

I'm running version 1.1 right now, and the patch in #11 can only be partially applied. I've also applied patches from the duplicate at http://drupal.org/node/1802916, but that didn't seem to work.

I just thought I would update this issue with a sandboxed module that I discovered https://drupal.org/sandbox/peem/1569354. This project looks promising and is exactly what I require and what is asked for in this issue. There maybe possibly an easier way to go about it. Seems to work well. Though I do have issues if I add field validation.

Status:Needs review» Needs work

The last submitted patch, 11: entityreference-autocomplete-1411304-9.patch, failed testing.

Version:7.x-1.x-dev» 7.x-1.1
Issue summary:View changes
StatusFileSize
new4.11 KB
FAILED: [[SimpleTest]]: [MySQL] 23 pass(es), 30 fail(s), and 6 exception(s).
[ View ]

Rolled #11 against 7.x-1.1, but this time keeping it as ($id) instead of [id:$id] when id's are not hidden.

Status:Needs work» Needs review

Lets see if this does anything.

Status:Needs review» Needs work

The last submitted patch, 26: entityreference-autocomplete-1411304-25.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new4.94 KB
FAILED: [[SimpleTest]]: [MySQL] 23 pass(es), 30 fail(s), and 6 exception(s).
[ View ]

#26 was looking correct in the autocomplete, but wasn't saving on submit, this time including the fix from #2185141-1: Required entity reference is possible to save with invalid, but tricky content. to allow saving.

Status:Needs review» Needs work

The last submitted patch, 29: entityreference-autocomplete-1411304-29.patch, failed testing.

Version:7.x-1.1» 7.x-1.x-dev
Status:Needs work» Postponed
StatusFileSize
new4.11 KB

New plan to address the non-saving issue, postponed on #1959624: Autocomplete widgets not referencing the single entity result, then this patch should apply, also rolled against dev this time.