In the exposed filter autocomplete options i have no fields to select in "Field with autocomplete results", it shows to me "Add some fields to view"

If i debug the code and change the line 48 like this it works:

if ($handler->field . '_value' == $this->realField) {

¿Maybe i'm missing something?

Comments

Carlitus created an issue. See original summary.

carlitus’s picture

Issue summary: View changes
Anonymous’s picture

I can confirm this.

This seems to be line 44 in the latest code.

Anonymous’s picture

Attached now a simple patch that solves the issue (for me).

trevorbradley’s picture

I *just* hit this myself.

A few notes:

Patch #4 applies against dev, not 1.2. (Should have read the patch filename to notice this)

Also, I'm not sure quite what's going on, but if I apply this patch, I can't get the "Add some fields to view" to work at all.

If I reverse the patch, then "Add some fields to view" works in some, but not all, of my views.

Anonymous’s picture

Trevor, I'm not sure I understand what you mean. Without the patch, I was not able to get views_autocomplete_filters to work, as it always just showed "Add some fields to view", even though the view had fields. As a result, autocomplete did not work (as it did not know from where to take the values for autocomplete). With the patch, I can select from the fields that have been added, and as default it shows the field used to filter (I haven't tried what happens if that field hasn't been added before). Autocomplete then works.

I don't know what you mean by 'I can't get the "Add some fields to view" to work at all.', because that is just a message that you should add fields to the view, and you do that in the usual place (so, if you don't have a field based view but display the entity in a display mode, you might need to force some fields, but I haven't tried that).

kallado’s picture

I still can't get it to work even with the patch. It still asks to "add some fields to view" does anyone have any update on this?
Thanks

kallado’s picture

Anonymous’s picture

Is your view display based on displaying the entities in a view mode or on fields? You add fields the usual way you add fields in views, and then better_exposed_filters can pick them up. But if no fields have been added to your view display because you display the entities, then that might be the problem.

The message "Add some fields to your view" suggests no fields have been added.

kallado’s picture

I have a lot of fields. Actually if comment the hole 'if' in the patch I can get them available on the select box the problem is that even image fields are available which is something we shouldn't want and the autocomplete only finds one element.

Anonymous’s picture

And you can't select any of them?

I have not really debugged this, only turned the solution by the original poster (which worked for me and allowed me to select from the fields) into a patch.

It probably requires some more debugging of if ($handler->realField . '_value' == $this->realField)

I'm afraid, as 1) it works for me and 2) I don't have time right now, I can only suggest to debug what the $handler object looks like compared to $this->realField.

kallado’s picture

Thanks anyway I was doing that already :). Unfortunately I don't have a lot of time to spare right now but as soon as I have any other info I'll post it

kallado’s picture

@carlitus @andreas-speck @trevorbradley
the patch doesn't work for me because the first element of the 'if' is $handler->field and not $handler->realField. Here's a patch that works for me.

Anonymous’s picture

It seems what we need to compare against depends on the field type.

This patch now does replace the test with the following:

      foreach ($this->view->display_handler->getHandlers('field') as $id => $handler) {
        if ($handler->field == $this->realField) {
          $field_options[$id] = $field_options_all[$id];
        } else if ($handler->field . '_value' == $this->realField) {
          $field_options[$id] = $field_options_all[$id];
        } else if ($handler->realField . '_value' == $this->realField) {
           $field_options[$id] = $field_options_all[$id];
        }
      }

This should take care of all the cases people had issues with (I hope).

Anonymous’s picture

Status: Active » Needs review
kallado’s picture

Thanks. It works for me, seams like it takes care of all the cases now.

bisw’s picture

It works for me too.

kallado’s picture

@carlitus @andreas-speck maybe it's time for someone to mark this as fixed

Anonymous’s picture

That depends on @vasike, the module maintainer, committing the patch.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
kris77’s picture

It works for me too.

Thanks @Andreas Speck

nasseralikarimi’s picture

#4 applied but not listed any data!

kallado’s picture

@na.karimi what patch have you aplied?

TonyMarc’s picture

I could not apply #14 to the current v1.2 because line 44 already contains

if ($handler->field == $this->realField) {

I adjusted the patch accordingly.

colan’s picture

Status: Reviewed & tested by the community » Needs work

There's far too much code duplication in the patch. Would be better to do something like:

if (in_array($this->realField, [
  $handler->field,
  $handler->field . '_value',
  $handler->realField . '_value',
])) {
  $field_options[$id] = $field_options_all[$id];
}
colan’s picture

Title: Add some fields to view » "Add some fields to view" option is always empty
Status: Needs work » Needs review
StatusFileSize
new8.47 KB
new8.67 KB

I implemented that, moved the section to its own method (as buildOptionsForm() is already too long), and removed some nesting.

aleevas’s picture

Thanks for all who working on this patch.
I've stacked with this issue too.
The patch from #26 almost solved this issue.
But it didn't apply for latest version of module (8.1.2).
Moreover in patch from #26 was missed the "autocomplete_combine_results" option.
So I made own patch, and hope it solve this issue.

aleevas’s picture

StatusFileSize
new8.33 KB
new1.37 KB

Sorry, I was wrong in my previous comment.
We don't have "autocomplete_combine_results" option in current branch.
It comes from another issue #3100867
So I removed this option from patch for this issue

aleevas’s picture

StatusFileSize
new8.35 KB

My previous patch successfully applied on dev branch, but not for the current version 8.x-1.2
I added patch for this version (for the tag 8.x-1.2)

colan’s picture

StatusFileSize
new2.42 KB

Cutting through some of the comments above, here's a helpful interdiff. As there's not much value introduced in #28, and given that it introduces many whitespace errors, let's ignore it. The exception is the following code, which should be fixed. So #26 is NW until this gets done (the other patches can be ignored as we need to fix this in HEAD):

+++ b/src/Plugin/views/filter/ViewsAutocompleteFiltersTrait.php
@@ -36,84 +36,105 @@ trait ViewsAutocompleteFiltersTrait {
+        '#title' => t('Minimum number of characters to start filter'),

Should be $this->t().

@aleevas: That's for catching it.

colan’s picture

Status: Needs review » Needs work
aleevas’s picture

StatusFileSize
new8.62 KB
new2.13 KB

@colan thanks for your review.
I've uploaded a new one patch for HEAD .
I hope it will be usefull

aleevas’s picture

Status: Needs work » Needs review
vasike’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Status: Needs review » Needs work

It seems there could be a related issue and its patch ...

So added as related issue to be taken into account ...

put it back in "Needs work" to make sure about related issue

colan’s picture

Status: Needs work » Needs review

Please don't create deadlock by setting a collection of independent issues to NW.

colan’s picture

  • colan committed 67e83b1 on 8.x-1.x authored by Andreas Speck
    Issue #2986201 by aleevas, colan, Andreas Speck, kallado, TonyMarc:...
  • colan committed ddc3f65 on 8.x-1.x
    Issue #2986201: Used OO method for translation.
    
colan’s picture

Status: Needs review » Fixed

Thanks everyone! There was still extra whitespace in #32 so I made the change from #30 in another commit.

Status: Fixed » Closed (fixed)

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

kallado’s picture

carlitus’s picture

Hi!, from my humble position, is it possible that since I have not uploaded a patch you have forgotten about me when awarding credits?

If it was a conscious thing then I accept it, it was just to make sure it wasn't an oversight.

Thank you!