Autocomplete with entity reference/relationship

Created on 17 March 2023, almost 2 years ago
Updated 27 April 2023, over 1 year ago

Problem/Motivation

Seems not to be working with entity reference/relationship on title field. Fields have same machine name. Tried different things.

First try was shown in this video for Drupal 7: Drupal 7 Views Autocomplete Filter Tutorial

Second attempt was to try both, title field and title filter give reference/relationship.

Unfortunately, nothing seems to work correct. The output of autocomplete isn't shown expected results, but when i type the title in hit enter, the output of the search result is right.

BTW: In that related issue, the author says, there's no "contains" option. This isn't my problem!

πŸ› Bug report
Status

Active

Version

1.4

Component

User interface

Created by

πŸ‡©πŸ‡ͺGermany KiLLAH89

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the β€œVDC” tag instead.

Sign in to follow issues

Comments & Activities

  • Issue created by @KiLLAH89
  • πŸ‡ΊπŸ‡ΈUnited States awolfey

    I'm having this issue also. I'm referencing a node from a group, and using an entity reference field.

  • πŸ‡ΊπŸ‡ΈUnited States ccloyd

    I had this issue with the 1.4 version. Reverted back to 1.3 and entity references work again. In the 1.4 version it appears to be an issue with the ViewsAutocompleteFiltersController.php file, specifically around line 220 in the autocomplete function.

  • πŸ‡¬πŸ‡§United Kingdom deranga

    Also ran into this issue whereby the update to 1.4 prevents the autocomplete from returning results.

    1.3, previously used the style plugin to render the result fields of the executed view, however the new method attempts to load the 'views machine named' field direct from the loaded result entity.

    Depending upon your use case, its possible as a workaround to reconfigure the exposed filter to behave in a similar fashion to 1.3, by unchecking either or both the "Unformatted dropdown" or "Unformatted suggestion" options to off. This then triggers the autocomplete to make use of the style plugin to render output as before.

    if (!$use_raw_suggestion || !$use_raw_dropdown) {
              $rendered_field = $style_plugin->getField($index, $field_name);
    }
    
  • πŸ‡«πŸ‡·France ericdsd France

    Thanks @deranga, for the workarround 8

    • vasike β†’ committed 69288848 on 8.x-1.x
      Issue #3348802: Fix Autocomplete with entity reference/relationship.
      
  • Status changed to Needs review over 1 year ago
  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

    Indeed this "capability" was lost.

    There is a new commit that should fix this.
    Could we have the confirmation, so we can close this?
    Thank you

  • πŸ‡©πŸ‡ͺGermany mvogel

    @vasike, great work that you found a way to distinguish between the entity and possible entity relationship. I tested it and it works almost 100%

    I have found a bug but I think it is a combination of this issue and https://www.drupal.org/project/views_autocomplete_filters/issues/3345680 πŸ› Attempt to read property "value" on null in src/Controller/ViewsAutocompleteFiltersController.php on line 220 Needs review

    Steps to reproduce:
    1. add a plain text field to node article (field_plain_text)
    2. add entity reference field to user pointing on node article (field_reference_field)
    3. create a node article with a filled field from (1) and update a user field_reference_field to this node
    4. create a user entity view with a page
    5. add "Relationships" to content from field_reference_field
    6. add a field from (1) to "Fields" and add "Filter criteria" with the exposed form and "Use autocomplete"
    7. visit the page from (4) and search for the value you created in (3)

    $real_field_name = $view_field->realField;
    

    $real_field_name = 'field_plain_text_value' for some reason see screenshot

    I hope you can reproduce it, it is kinda hard to explain, if you need a video or want a call you can write me

  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

    @mvogel thanks ... this is not about relationship ... it's about views data ... so good catch ... please check the latest code and the other issue ... where i pushed the commit.

  • Status changed to Fixed about 1 year ago
  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

    i think we can close this.

    please, feel free to re-open, if not done.

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

  • Status changed to Fixed about 2 months ago
  • πŸ‡¬πŸ‡§United Kingdom mistergroove

    Having the same issue with relationship - no values are returned from the callback:

    http://myserver/views-autocomplete-filters/protocols/block_method/title/0?q=john

    Also I noticed I changed the filter identifier from 'title' to 'author'. Should this also be reflected in the url?

    Anyone else still having this issue?

Production build 0.71.5 2024