From UX stand point, having the unique identifier is confusing for non-savy users. Let's have an option to remove this.

Files: 
CommentFileSizeAuthor
#14 1802916-er-show-identifier-14.patch5.39 KBRoySegall
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]
#9 1802916-er-show-id-option-9.patch6.58 KBAmitaibu
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]
#5 1802916-er-show-identifier-5.patch5.29 KBAmitaibu
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]
#3 1802916-er-show-identifier-3.patch5.84 KBAmitaibu
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]
#1 1802916-er-show-identifier-1.patch2.69 KBAmitaibu
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new2.69 KB
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]

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

Bottom line -- look at other modules, such as http://drupal.org/project/autocomplete_deluxe

amitaibu: DamZ: btw, are you ok with such a feature -- http://drupal.org/node/1802916 ?
[12:03pm] c-g: http://drupal.org/node/1802916 => Add option to autocomplete widget to hide term ID => Entity reference, Code, normal, needs review, 0 comments, 1 IRC mention
[12:09pm] DamZ: amitaibu: no, I'm not ok with this
[12:09pm] DamZ: amitaibu: this is really just an issue with the Autocomplete widget we are using
[12:09pm] DamZ: ie. the core one
[12:09pm] amitaibu: DamZ: this is for when I select a single bundle
[12:10pm] DamZ: nothing forces you to use the core autocomplete widget, as there are altenatives
[12:10pm] amitaibu: DamZ: sure, possible. but didn't understand the problem with the core widget
[12:10pm] DamZ: amitaibu: bojanz: ok, here we are: http://drupal.org/node/1803064
[12:10pm] c-g: http://drupal.org/node/1803064 => Horizontal extensibility of Fields: introduce the concept of behavior plugins => Drupal core, field system, normal, active, 0 comments, 1 IRC mention
[12:11pm] DamZ: amitaibu: well, the core widget displays to the user the key, so we have to put the key somewhere in the text
[12:12pm] DamZ: most of the times, the label is not unique, it's just happens to be unique for taxonomy terms belonging to the same vocabulary, but even that is britle
[12:12pm] DamZ: we don't even have a unique key on the term name in the database
[12:13pm] amitaibu: DamZ: yeah, my problem isn't the concept, I'm thinking about UX (and about my client) -- where they say, I'll make sure nothing is duplicate, but keep the widget simple
[12:13pm] DamZ: amitaibu: yes, and my answer is "don't use core autocomplete"
[12:13pm] amitaibu: DamZ: so the option is enabled by default. I can also improve the description about implicaton
[12:13pm] amitaibu: i see
[12:14pm] amitaibu: DamZ: but just checked, the term reference doesn't add an entity ID https://skitch.com/amitaibu/ess3w/edit-article-tetes-site-install
[12:14pm] DamZ: amitaibu: yes, as I said "most of the times, the label is not unique, it's just happens to be unique for taxonomy terms belonging to the same vocabulary, but even that is britle"
[12:16pm] amitaibu: DamZ: yeah, I understand that, and I understand why it *might* be problematic, but If I take care of the duplication, I think it would be nice (==in ER) to have an option to remove the entity ID. The description can say "Make sure you don't have duplicate bla bla"
[12:18pm] amitaibu: DamZ: are you sold, or should I let go?
[12:18pm] DamZ: amitaibu: I think implementing any other autocomplete widget would be a far better solution
[12:19pm] DamZ: for example based on http://drupal.org/project/active_tags
[12:19pm] DamZ: or any 1000s of libraries that do that
[12:20pm] DamZ: or http://drupal.org/project/autocomplete_deluxe
[12:20pm] amitaibu: DamZ: but don't all those widgets that don't have an entity ID have the same issue of duplication?
[12:21pm] amitaibu: DamZ: I have no problem using other/ writing custom widget, I'm just thinking there's a need for this we can solve in ER provided we properly document it
[12:21pm] DamZ: or maybe even Chose
[12:21pm] DamZ: or maybe even Chosen
[12:22pm] DamZ: amitaibu: I think it would be better for everybody to have a better autocomplete supported in Entity Reference
[12:22pm] DamZ: do you disagree?
[12:22pm] DamZ: your approach is very very one-off
[12:24pm] amitaibu: DamZ: no, I don't disagree, what I don't understand, maybe I don't know deluxe well enough, is how it prevents the duplication if it doesn't show the entity ID
[12:25pm] amitaibu: DamZ: as I understand it just does the entity selection, only in a fencier way
[12:25pm] DamZ: amitaibu: it stores the key, but only displays the label to the user
[12:25pm] DamZ: which is what you want
[12:26pm] amitaibu: DamZ: yap, that's exactly what my Patch is trying to do. Store key but show label
[12:26pm] DamZ: amitaibu: your patch only displays the label, and tries to find the key based on the label
[12:27pm] DamZ: amitaibu: a better autocomplete should (1) only display labels to the user, but (2) post the key to the server
[12:27pm] amitaibu: DamZ: ok, now we're on the same page.

Status:Closed (won't fix)» Needs review
StatusFileSize
new5.84 KB
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]

http://drupal.org/project/autocomplete_deluxe doesn't solve the issue in any better way. A separate issue should be to integrate AD with ER.

Attached patch improves:

  • Validation in case there's no entity ID and there are duplicate labels we select the first one
  • Better description on the implication of unchecking this checkbox

Definitely gets a +1 from me -- users on my site have been asking me what the number in brackets mean and getting confused by it.

+++ b/plugins/selection/EntityReference_SelectionHandler_Generic.class.php
@@ -212,24 +212,27 @@ class EntityReference_SelectionHandler_Generic implements EntityReference_Select
+          form_error($element, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)"', array(

As for this, I think that finding the ID of the entity is too complex a task for a lot of users. (Also, as an identification method it seems a bit weak to me: what if you make a typo and put spaces in the parentheses or something like that? I don't trust my pwn fringers not to make tpyes. No kidding, this is what I typ like ;)

+++ b/entityreference.module
@@ -871,8 +881,6 @@ function _entityreference_autocomplete_validate($element, &$form_state, $form) {
       // autocomplete but filled in a value manually.
-      $field = field_info_field($element['#field_name']);
-      $handler = entityreference_get_selection_handler($field);
       $field_name = $element['#field_name'];

This looks like an unrelated clean-up.

StatusFileSize
new5.29 KB
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]

> This looks like an unrelated clean-up.

Yeah, I diffed after pushing that fix. re-rolled.

Title:Add option to autocomplete widget to hide term IDAdd option to autocomplete widget to hide entity ID

Better title

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

That's great, but given there's a pretty good-looking patch here and no movement on that issue in ages, might it not be better to commit this patch here in the meantime?

StatusFileSize
new6.58 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]

Still need this for a make file...

#9 was exactly what I was looking for. Works for me.

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

Reopening, as I think there is a clear case for this feature.

I take it back, seems to have broken my autocomplete and doesnt give any results. Will see if I can figure out why.

UPDATE:

Patch seemed to have removed necessary $matches and foreach loop from get_matches callback. Should look like this for autucomplete to work again:

   if (isset($tag_last)) {
        // Get an array of matching entities.
        $entity_labels = $handler->getReferencableEntities($tag_last, $instance['widget']['settings']['match_operator'], 10);
        // Loop through the products and convert them into autocomplete output.
        $show_identifier = $instance['widget']['settings']['show_identifier'];
        foreach ($entity_labels as $values) {
            foreach ($values as $entity_id => $label) {
                $key = $show_identifier ? "$label ($entity_id)" : $label;
                // Strip things like starting/trailing white spaces, line breaks and tags.
                $key = preg_replace('/\s\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key)))));
                // Names containing commas or quotes must be wrapped in quotes.
                if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
                    $key = '"' . str_replace('"', '""', $key) . '"';
                }
                $matches[$prefix . $key] = '<div class="reference-autocomplete">' . $label . '</div>';
            }
        }
        drupal_json_output($matches);
    }
}

But it doesnt save my selection.

nope, I cant figure it out. If i use the patch in 9 I get no results. If I put the code I put above back in, I get results but it wont save (i think due to the autocomplete validate function requiring the entity id to do the preg match on).

StatusFileSize
new5.39 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]

@7wonders is right, the patch seems to remove the $matches and therefor we don't get auto complete.

I attached a re rolled patch.

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

#14 and its related other patches are not working. I am worried. Is there any other solution ? How can we remove tid when we choose taxonomy term in autocompleted field using entity reference ?

Regard's
Ritu Raj

You can use the chosen ajax like someone suggested earlier

I tried to enable to chosen ajax but it dependencies on chosen module which must be >= 7.2 version. I haven't found this module in 7.2 version. Drupal provide in 7.x-1.0 version.

:( .. Please help ..

I remember that there was a patch for chosen ajax and the version problem. Try to download the dev version of the chosen ajax module

Apparently there were some unrelated changes that broke this functionality. The patch here is also required now to allow the patch in #9 to work:

https://drupal.org/node/1389238#comment-7588151

Status:Needs review» Needs work

The patch in #14 does not work for me, it gets rid of the entity id but after saving my field is empty. The patch mentioned in #21 does not help either.

Has there been any update on this issue?

no idea, but those brackets are really confusing - they actually warrant their own block to remind users to just "ignore them" :)

at any rate, there was some work on Chosen to create Chosen Ajax to *Specifically* address this "number in brackets" issue

for those interested in the code or what they are doing: https://drupal.org/project/chosen_ajax

Issue summary:View changes
Status:Needs work» Closed (duplicate)
Related issues:+#1411304: Autocomplete widget improvements