If I enter any numeric value into the search field, the autocomplete list correctly returns a list of suggestions beginning with the numbers I entered. If I then select a number from the list, it always returns a single digit value between 0 and 3. For example, if I select "4313" from the list, "0" is filled in instead of "4313." If I type in "4313" and ignore the autocomplete list, the search results are correct. I tested with both the custom and Drupal widgets and got the same results.

Our current project - when we roll out this next month - will encourage users to search by zip code. Has anyone else experienced this issue or is it just my setup/configuration? Thanks for your help.

Comments

vanillawater’s picture

Priority: Normal » Major

Same here.
It returns the array key instead of the selected numeric value.

Thanks

com_net’s picture

+1 subscribe

butler’s picture

Same here subscribe

marcoka’s picture

same here, too

janusman’s picture

Status: Active » Needs review
StatusFileSize
new1.68 KB
new1.85 KB

This problem is PHP related: the suggestions array built inside the suggesting functions could look, say, like this:

// Searching for "14"
$suggestions = array(
  '14' => '... HTML that shows in the autocomplete widget ...',
  '14 things' => '...',
  '14 books' => '...',
);

but when that array is returned, PHP insists the FIRST key is not the string "14", but an integer... and thus replaces the key 14 with a 0, so it looks like this when you var_export() it:

$suggestions = array(
  0 => '... HTML that shows in the autocomplete widget ...',
  '14 things' => '...',
  '14 books' => '...',
);

So this is a patch that forces all indexes to be a string by prepending a "*" to all keys on the array, which is then removed before being shipped back to the browser.

Please review!

Note: Patches for both D6 and D7.

janusman’s picture

Status: Needs review » Fixed

Committed to 6.x and 7.x (HEAD) branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

rhymeswithcamera’s picture

Thanks for fixing this! Works beautifully now.