When using autocomplete feature, it retrieves data while i type. This is ok.
But when i select a matching word , the text field is populated with the number coresponding with the word found in 'matches' array and not with the selected word as it should be.

If i change line:
     li.autocompleteValue = key;
with:
     li.autocompleteValue = matches[key];
it seems to work fine.

Is this a bug, or am I missing something?

Original Code (in autocomplete.js):

.......

var ul = document.createElement('ul');
var ac = this;
for (key in matches) {
var li = document.createElement('li');
$(li)
.html('

'+ matches[key] +'

')
.mousedown(function () { ac.select(this); })
.mouseover(function () { ac.highlight(this); })
.mouseout(function () { ac.unhighlight(this); });
li.autocompleteValue = key; //------------------------ here is the line (212)---------------
$(ul).append(li);
}

.......

CommentFileSizeAuthor
#1 example.jpg125.15 KBcoolboygfx

Comments

coolboygfx’s picture

StatusFileSize
new125.15 KB
rfay’s picture

I actually have had to copy and enhance autocomplete.js to use it for my own purposes before. On the other hand there are lots of successful examples of its use.

I'll see if I can take a look at this. It's been a while.

rfay’s picture

Category: bug » support
coolboygfx’s picture

Ok I've found that I've made a mistake in my test module.

My previous module function for construct autocomplete result was:

function research_autocomplete($string)
{
	$matches = array('ajax', 'archery', 'agile');
	print drupal_to_js($matches);
}

In fact this function should be:

function research_autocomplete($string)
{
	$matches = array('ajax'=>'ajax', 'archery'=>'archery', 'agile'=>'agile');
	print drupal_to_js($matches);
}

Conclusion: autocomplete.js display in drop down values from the returned array, but when selecting one it selects the key
for that value.

But, i do not understant the logic behind duplicating array values to array keys while we are only interested in values.
Anyway I'll do that.

coolboygfx’s picture

Status: Active » Closed (works as designed)

I close this issue.