user profile in my site have a field called "field_true_name" to store user true name.

I create a field "field_user_ref" in a content type which refer to an certain user, and the field type is entity reference,widget type is autocomplete, and I create a view with a display of entity reference for searching.also I setup the "searching fields" of style option include the "field_true_name" of user profile.

what I found out is it's didn't work. this views can only search out the user by user name, but not field_true_name.

if I change widget type to select list,it can show all the user,but as you know, quite a lot of items can make it crash.

so is there some problem with the module?or I make any wrong step?thank you in advance.

PS:The issue is quite similar to http://drupal.org/node/1194086 except the module is not entity reference.

CommentFileSizeAuthor
#1 patch-entityreference-7.x.patch1.13 KBb1101
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

b1101’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc3
Status: Active » Needs work
FileSize
1.13 KB

not sure what will work stably in future

cn_gd’s picture

hi b1101, thank you for your patch.it works fine when the field_true_name all in English but not works when it contain Chinese charater.It's still can't search my target field out.

so is there a patch works for UTF8 encoded field?

b1101’s picture

I have worked with the Russian character set (UTF-8)

cn_gd’s picture

thank b1101, I found it 's problem with autocomplete in firefox,and I fix it with the patch in #17 of http://drupal.org/node/812354

the patch is: http://drupal.org/files/autocomplete_2.patch

cn_gd’s picture

this patch seen to not work relation with entity reference in views.

Alan D.’s picture

Category: bug » feature
Priority: Critical » Major

Personally, this seems like a feature request. Changed settings to reflect this and to assist with #1647996: Entity Reference needs a 1.0 release as part of the Drupal.org D7 Upgrade Initiative.

Shyghar’s picture

Hi,
I have the same problem. I want to search user by field_first_name and field_last_name instead by username.
I used the patch in #1 but now (typeing for example 'j') i have this error back:

An AJAX HTTP error occurred.  
HTTP Result Code: 200  
Debugging information follows.    
Path: https://mysite.com/entityreference/autocomplete/single/field_sender/node/shipment/23   
StatusText: OK  
ResponseText: {  
"John Doe (10)":" [lot of data..] ",
"Jon Thom (7)":" [lot of data..] ",
"Jane Doe (1)":" [lot of data..] "}

jQuery.extend(Drupal.settings, {"thmr_1":{"id":"thmr_1","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":10.43,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_first_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_first_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_first_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_first_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_first_name","views_view_field__users_autocomplete","views_view_field__field_first_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_2":{"id":"thmr_2","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":0.42,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_last_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_last_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_last_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_last_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_last_name","views_view_field__users_autocomplete","views_view_field__field_last_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_3":{"id":"thmr_3","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":0.3,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_first_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_first_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_first_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_first_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_first_name","views_view_field__users_autocomplete","views_view_field__field_first_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_4":{"id":"thmr_4","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":0.29,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_last_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_last_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_last_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_last_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_last_name","views_view_field__users_autocomplete","views_view_field__field_last_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_5":{"id":"thmr_5","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":0.3,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_first_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_first_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_first_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_first_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_first_name","views_view_field__users_autocomplete","views_view_field__field_first_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_6":{"id":"thmr_6","name":"views_view_field","used":"theme_views_view_field","type":"func","duration":0.3,"candidates":["views_view_field__users_autocomplete__entityreference_1__field_last_name","views_view_field__users_autocomplete__entityreference_1","views_view_field__entityreference_1__field_last_name","views_view_field__entityreference_1","views_view_field__users_autocomplete__entityreference__field_last_name","views_view_field__users_autocomplete__entityreference","views_view_field__entityreference__field_last_name","views_view_field__entityreference","views_view_field__users_autocomplete__field_last_name","views_view_field__users_autocomplete","views_view_field__field_last_name"],"preprocessors":["template_preprocess_views_view_field"],"processors":[]},"thmr_7":{"id":"thmr_7","name":"views-view-fields.tpl.php","used":"sites\/all\/modules\/views\/theme\/views-view-fields.tpl.php","type":"tpl","duration":0.79,"candidates":["views-view-fields.tpl.php"],"preprocessors":["template_preprocess","template_preprocess_views_view_fields","contextual_preprocess"],"processors":["template_process","rdf_process"]},"thmr_8":{"id":"thmr_8","name":"views-view-fields.tpl.php","used":"sites\/all\/modules\/views\/theme\/views-view-fields.tpl.php","type":"tpl","duration":0.67,"candidates":["views-view-fields.tpl.php"],"preprocessors":["template_preprocess","template_preprocess_views_view_fields","contextual_preprocess"],"processors":["template_process","rdf_process"]},"thmr_9":{"id":"thmr_9","name":"views-view-fields.tpl.php","used":"sites\/all\/modules\/views\/theme\/views-view-fields.tpl.php","type":"tpl","duration":0.68,"candidates":["views-view-fields.tpl.php"],"preprocessors":["template_preprocess","template_preprocess_views_view_fields","contextual_preprocess"],"processors":["template_process","rdf_process"]},"request_id":"414212549500fb56c146fb","devel_themer_uri":"\/devel_themer\/variables\/414212549500fb56c146fb"});

Anyone can explain me the problem?

Alan D.’s picture

Category: feature » bug

Sorry, after exploring some of the options that the module provides, I shouldn't have changed this ;)

bunthorne’s picture

I think my problem is similar: I have a Content Type "Venue" with a Title and Addressfield element, and an Entity Selection view with the fields specified and the Entity Selection settings pointing to search each of the fields in the View (Title, Address;Company, and Address:Address fields). I have a separate Content Type "Performance" that uses Entity Selection mode to use the Venue Selection entity reference view, autocomplete widget.

In practice, the autocomplete only matches on the Venue Title. It does not match any Address field components.

Am on the right bug report?

lpeabody’s picture

I believe I'm experiencing the same problem. I have a custom field, field_complete_name attached to a User entity. I have a view setup with an entity display and it clearly works with a select list, but auto-complete fails 100% of the time. Nothing is returned in the response, even though it's a 200 OK. Definitely a bug report for sure.

alieffring’s picture

This issue also applies to fields in a node which are not columns in the node table, i.e. essentially the only thing that works is searching by title. Attempting to search by any other field will actually search by nid, because $this->view->field[$field_alias]->field_alias is always "nid" instead of the actual alias of the field. I'm sure Views has good reasons to do it that way, but it's decidedly not what we want here.

claudiu.cristea’s picture

Title: can't search user by field of profile other than username in autocomplete widgets » Autocomplete searches only on entity properties (not fields)
Version: 7.x-1.0-rc3 » 7.x-1.x-dev
Component: Code » User interface
Status: Needs work » Reviewed & tested by the community

#4 is fixing the issue. Tested with Views.

claudiu.cristea’s picture

Title: Autocomplete searches only on entity properties (not fields) » Autocomplete is searching only on entity properties (not fields)
magtak’s picture

Status: Reviewed & tested by the community » Active

Neither #1 (breaks the searching *even* for the title) nor #4 (was using chrome anyway) works.

In my case, the view is searching for users with a relationship to their profile2 profiles which contain their first and last names.

The autocomplete textbox only searches within the users' login names and emails and not their profile2 information.

magtak’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc3
mojiro’s picture

Working also with translated fields from Entity Translation & Title modules

lpeabody’s picture

I'm still experiencing this problem after being upgraded to rc5.

EDIT: Though applying the patch from #1 fixed it for me.

vadimk’s picture

My hacky fix.

/**
 * Implements hook_views_query_alter().
 */
function MY_MODULE_views_query_alter(&$view, &$query) {
  if ($view->name == 'VIEW_NAME') {
    $pattern = arg(7);
    if (!empty($pattern)) {
      $options = $view->display_handler->options['entityreference_options'];
      $style_options = $view->display_handler->options['style_options'];
            
      $value = db_like($options['match']) . '%';
      if ($options['match_operator'] != 'STARTS_WITH') {
        $value = '%' . $value;
      }
      
      $conditions = db_or();
      if (!empty($style_options['search_fields']['name'])) {
        $conditions->condition('users.name', $value, 'LIKE');
      }
      
      foreach ($style_options['search_fields'] as $field_alias) {
        if (substr($field_alias, 0, 6) == 'field_') {
          $join = new views_join();
          $join->definition = array(
            'table' => 'field_data_' . $field_alias,
            'field' => 'entity_id',
            'left_table' => 'profile_users',
            'left_field' => 'pid',
            'type' => 'LEFT',
          );
          $join->construct();
          $query->add_relationship($field_alias, $join, 'profile');
          $conditions->condition($field_alias . '.' . $field_alias . '_value', $value, 'LIKE');
        }
      }
      
      if (isset($query->where[0])) {
        unset($query->where[0]);
      }
      
      $query->add_where(NULL, $conditions);
    }
  }
}
stupiddingo’s picture

Patch #1 was successful at allowing fields on nodes to be searchable with rc5. Commit to next release?

magtak’s picture

Agree with #19, also worked on rc3, surprised it wasn't commited.

spacereactor’s picture

#1 doesn't fix all field search, profile2 field can't be search.

spacereactor’s picture

I try autocomplete to search the another entity reference field in label but it doesn't work, but it work if i change the entity reference field from label to entity id than i able to search found it. Can this be fix?

kingman1016’s picture

I can confirm #1 made fields in a field collection item searchable.

Dave Reid’s picture

Version: 7.x-1.0-rc3 » 7.x-1.x-dev
Status: Active » Reviewed & tested by the community

Just attempted #1 and it fixed the issue of being able to search on field values. Marking as RTBC.

hanoii’s picture

amitaibu’s picture

Status: Reviewed & tested by the community » Fixed

Fixed coding style and committed, thanks.

Zippy’s picture

Hi,
the patch is not fully working for me. I try to use an autocomplete field (entity reference / a view is associated) inside a fieldcollection. For now it only works for normal content types...

regards

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

andrewyager’s picture

Status: Closed (fixed) » Reviewed & tested by the community

This patch does not look like it has been applied to Entity Reference, but I've tested and it works.

Moving back to RTBC - if it has in fact been applied the issue should be updated to reflect that it has been applied.

andrewyager’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Derr. I should read the notes.

jcam88’s picture

Issue summary: View changes

FYI. Anyone interested in autocomplete search must strongly consider using https://drupal.org/project/search_autocomplete.

Checkout this issue which describes how you can use the module for entity reference autocomplete fields.
https://drupal.org/node/2192197

supriyarajgopal’s picture

Hi,

This patch has already been applied to 7.x-1.1 but it is still not working for entity reference view having a field collection field.

Any help is appreciated,

Regards,
Supriya Rajgopal