Hi. It would be nice if you'll add an option for autosubmitting autocomplete forms.

drupal_add_js("Drupal.behaviors.autocomplete_element = function (context) {
    $('input.autocomplete').result(function(event, data, formatted) {
      $(this).parentsUntil('form').parent().submit();
    });
  }", 'inline');

Comments

jerome72’s picture

I also really need this functionality. I added the code provided by ivanjaros in my custom module, but it didn't work: there is no autosubmit :(

Here's my code :

function autocomp_formulaire()
{
  drupal_add_js("Drupal.behaviors.autocomplete_element = function (context) {
    $('input.autocomplete').result(function(event, data, formatted) {
      $(this).parentsUntil('form').parent().submit();
    });
  }", 'inline');
  $sql = db_query("SELECT infos, telephone FROM {agent_autocomplete}");
  $infos = array();
  while ($data = db_fetch_object($sql)) {
    $infos[] = $data->infos . '<br>' . $data->telephone;
  }
  $form['autocomplete_element'] = array(
    '#type' => 'autocomplete',
    '#data' => $infos,
    '#plugin_options' => array('matchContains'=>TRUE),
  );
  
  return $form;
}

Any help would be greatly appreciated.

jerome72’s picture

I finally managed to make it Work !

  drupal_add_js("Drupal.behaviors.autocomplete_element = function (context) {
    $('#MyInputId').result(function(event, data, formatted) {
    $('#MyFormId').submit();
    });
    }", 'inline');