The autocomplete field currently searches from the beginning of the state/province data.

I'd like to see the autocomplete fields to have the option of "first" (currently implemented) or "contains", as is found in the CCK autocomplete field.

In Italy, there are many regions such as: "Verbano-Cusio-Ossola" where the "contains" option would help the users a lot.

Comments

yesct’s picture

What would it take to implement this? Is it just a flag, or would code have to be written?

Andrewsuth, If you can post patch or more details about how to make the change, then maybe some people could try it out on their data, and post some feedback about whether this change would have only an upside, or if it might need more consideration.

it sounds useful to me... :)

andrewsuth’s picture

Unfortunately I don't have time to make a patch at the moment but here are the key functions for this feature:

This is taken from CCK autocomplete: autocomplete.module, lines 861-873:

  if ($string !== '') {
    $match_operators = array(
      'contains' => "LIKE '%%%s%%'",
      'equals' => "= '%s'",
      'starts_with' => "LIKE '%s%%'",
    );
    $where[] = 'n.title '. (isset($match_operators[$match]) ? $match_operators[$match] : $match_operators['contains']);
    $args[] = $string;
  }

In the case of this module, contains, equals and starts_with are set in the widget, (line 411-429):

    case 'form':
      $form = array();
      $match = isset($widget['autocomplete_match']) ? $widget['autocomplete_match'] : 'contains';
      if ($widget['type'] == 'nodereference_autocomplete') {
        $form['autocomplete_match'] = array(
          '#type' => 'select',
          '#title' => t('Autocomplete matching'),
          '#default_value' => $match,
          '#options' => array(
            'starts_with' => t('Starts with'),
            'contains' => t('Contains'),
          ),
          '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
        );
      }
      else {
        $form['autocomplete_match'] = array('#type' => 'hidden', '#value' => $match);
      }
      return $form;

There is a little more code but you should look through these functions in the module to get an idea of how it works.

ankur’s picture

Category: feature » support
Status: Active » Closed (fixed)

I'm thinking since there isn't too much demand for this issue, it can be resolved as a one-off in your situation using hook_form_alter() and modifying the #autocomplete_path attribute in the form array for the province field. Another possibility is to use hook_menu_alter() to change the callback for the current #autocomplete_path and replace it with a custom function for providing the list of autocomplete options.