i have one field setting with a autocomplete and i would like to force user to select autocomplet suggestion

something like this : http://demo.mysamplecode.com/JQuery/pages/dropdownUsingAutoComplete.jsp

How can i achieve this with drupal

my field :

            $form['myfield'] = array(
		'#type' => 'textfield',
		'#size' => 35,
		'#required' => true,
		'#autocomplete_path' => 'autocompletecpville',
	 );

Comments

ey’s picture

Did you find any solution for that? Thanks.

Old usernames: pc-wurm, Елин Й.

crosstopher’s picture

In case anyone else stumbles across this thread, I solved this issue by putting the following code into a js file served up by my theme, tweaking the built in function:

Drupal.jsAC.prototype.onkeydown = function (input, e) {
  if (!e) {
    e = window.event;
  }
  switch (e.keyCode) {

  	case 13:    // If the users presses enter without making a selection, default to the top hit.

      if (!($('#autocomplete ul li.selected')[0])) {
          this.selectDown();
          return true;
      }
      return false;

    case 40: // down arrow.
      this.selectDown();
      return false;
    case 38: // up arrow.
      this.selectUp();
      return false;
    default: // All other keys.
      return true;
  }
};