Custom autocomplete form and autosubmit I've added an autocomplete function for my views_exposed_form (a text input) using this tutorial and it works (https://www.linkedin.com/pulse/implementing-autocomplete-drupal-8-custom-callbacks-waliullah-khan).

I'd like to add a "submit on click" behaviour, so when I click on a value of the autocomplete it changes the value of the input and then submit the form.

How should I do this?
Attaching below code:

custom.module

&lt;?php

use Drupal\Core\Form\FormStateInterface;

function custom_form_alter(array &amp;$form, FormStateInterface $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
    if ($form['#id'] == "YOUR_FORM-ID") {
      $form['combine']['#autocomplete_route_name'] = 'custom.autocomplete';
      $form['#attached']['library'][] = 'custom/custom';
      $form_state-&gt;setCached(FALSE);
    }
  }
}


custom.routing.yml

custom.autocomplete:
  path: '/want/autocomplete'
  defaults:
    _controller: '\Drupal\custom\Controller\WantAutoController::autocomplete'
  requirements:
    _permission: 'access content'


custom.libraries.yml

custom:
  version: 0
  js:
    js/custom.js: {}
  dependencies:
    - core/jquery


js/custom.js

(function ($) {
    Drupal.behaviors.custom = {
        attach: function (context) {
            $("#FIELD-ID").autocomplete({
                select: function (event, ui) {
                    if (ui.item) {
                        var itemLink = $(ui.item.label).attr('href');
                        window.location.href = itemLink;
                    }
                }
            });
        }
    };
}(jQuery));


src/Controller/WantAutoController.php

&lt;?php

namespace Drupal\custom\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
 * Returns tree responses for nodes.
 */
class WantAutoController extends ControllerBase {


  function autocomplete(Request $request) {
    $db_conn = \Drupal::database();
    $matches = [];
    $string = $request-&gt;query-&gt;get('q');
      $alias = \Drupal::service('path.alias_manager');
      $db_conn = \Drupal::database();
      $query = $db_conn-&gt;select('node','n');
      $query-&gt;leftJoin('node_field_data', 'nfd', 'nfd.nid = n.nid');
      $query-&gt;fields('n');
      $query-&gt;fields('nfd',['title']);
      $result = $query-&gt;execute()-&gt;fetchAll();
      if ($results) {
        foreach ($results as $row) {
          $path = $alias-&gt;getAliasByPath('/node/' . $row-&gt;nid);
          $linkTonode = '&lt;a href="' . $path . '"&gt;' . $row-&gt;title . '&lt;/a&gt;';
          $matches[] = ['value' =&gt; $row-&gt;title, 'label' =&gt; $linkTonode];
        }
      }
    return new JsonResponse($matches);
  }

}


Here in the autocomplete we are building value with "a" tag. And while searching autocomplete field our autocomplete return with "a" tag also. We are also building js here to click on that value and redirect.