XF 2.0 AutoComplete for custom data

Jake B.

Well-known member
I want to take XF's auto complete function and use it for custom data, though this doesn't not seem possible to do without completely copying functions from core.js. There is another auto complete method that is used for a few things (users on conversations, tags, etc) which supports defining a URL but I can't find a way to limit this to a single value only. Any particular reason the ac="single" method doesn't support anything other than users?
 
We use the existing system to autocomplete template names in template modifications, so you may want to look at how that works as an example.
 
Adding to the above, is there a way to retrieve the id value of the autosuggest selection when clicked? From the controller code, it seems that we are passing something like:
PHP:
$viewParams[] = [
    'id' => 1,
    'text' => 'Abc'
];

$viewParams[] = [
    'id' => 2,
    'text' => 'Def'
];

$viewParams[] = [
    'id' => 3,
    'text' => 'Ghi'
];


$view = $this->view();
$view->setJsonParam('results', $viewParams);
return $view;

but I couldn't find a way to access the "id" part of the result.
 
So after a little digging, I see where the li is getting generated; was thinking of adding the id value as a data-attribute on the li tag. Unfortunately if my understanding is correct, I won't be able to extend the XF.AutoCompleteResults's showResults() method due to:
  • It being present in the js/xf/core.js file
  • Not a handler that can be extended going by the XF.create() declaration
Would be wonderful if my assumption is wrong though.
 
Back
Top Bottom