Hi there and thanks for this great module. I've been using it for a few days and realised that the autocomplete wasn't taking into account any arguments for the view it was in. That meant that if I had my 'Action to take if argument is not present' set to 'Display empty text' then no matter what was entered in the autocomplete box, it would say no results were found - the only way around this was to set the action to 'Display all values', but that wasn't ideal either as it meant that the autocomplete results weren't limited by the argument in any way.

So I decided to add my own very basic argument support in. The way it works is:

  • In views_autocomplete_filters_form_views_exposed_form_alter it grabs the views arguments and implodes them into a comma-separated string. (Any suggestions for a better way of doing this are welcome.)
  • The argument string, if present, gets appended to the #autocomplete_path.
  • The menu callback now accepts the argument and explodes it back out into an array.
  • A check is made to see if arguments are present; if so, the view's arguments are set; if not, then it readjusts the variables accordingly.

(Since the $arguments variable precedes the $string in the menu callback arguments, if it is not present then the search string is assigned as the $arguments array, leaving an empty $string variable; e.g. the search string 'findme' with an argument of 8 forms the path autocomplete_filter/view-name/view-display/8/findme, but with no argument at all it forms the path autocomplete_filter/view-name/view-display/findme. Since the string in position 3 is read in as $arguments, we simply check for a non-existent $string and assign it the value of $arguments, plus skip setting arguments for the view.)

I haven't tried this with multiple arguments, but think it should work. I may be wrong, so give it a go!

I'll attach a patch. It's my first time at making a patch so please excuse me if it's not the correct format.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

LGLC’s picture

Status: Active » Needs work
FileSize
3.11 KB

Patch attached.

Raf’s picture

Thanks! Had the same problem, and looked to see if someone made a patch (so I didn't have to make it myself :P ). Your patch works like a charm!

_vid’s picture

Status: Needs work » Needs review
FileSize
3.06 KB

I wanted to try this in 7.x-1.0-beta2 so I made the D7 version of your changes.
There may be a few other places to update too.
I'm interested auto-completing the views arguments and not the filters so this may be a step in that direction.
I added 'do-not-test' to the patch since it's for a different version than this issue's patch.

Also set the status to needs review to see if the original patch passes testing.

mrfelton’s picture

Version: 6.x-2.1-beta1 » 7.x-1.x-dev

7.x is the active version now so updating the issue version to 7.x.

vasike’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#1871382: Autocomplete not taking arguments into account