Bug Tracker

Opened 11 years ago

Closed 11 years ago

#3448 closed bug (invalid)

[autocomplete] 'options.multiple' not fully disabled when false

Reported by: proasailor Owned by:
Priority: major Milestone: 1.3
Component: plugin Version: 1.2.6
Keywords: Cc:
Blocked by: Blocking:

Description

There are four references to function 'trimWords()' in the jquery.autocomplete.js code; three of them are "protected" by a check of 'options.multiple'; that is to say, 'trimWords()' is called only if 'options.multiple' is true.

This bug is caused by the 4th reference (actually the first in the source code), on line 185, which calls 'trimWords()' regardless of 'options.multiple':

$.each(trimWords($input.val()), function(i, value) {
	request(value, findValueCallback, findValueCallback);
});

The fix is VERY SIMPLE! Just add the check within the 'trimWords()' function as follows:

function trimWords(value) {
	if ( !value ) {
		return [""];
	}
	if ( !options.multiple ) {
		return [value];
	}
	...

Doing it this way allows the test to be removed from function 'lastWord()':

function lastWord(value) {
	var words = trimWords(value);
	return words[words.length - 1];
}

Without this fix, autocomplete consistently fails when the 'search()' method is used.

Change History (3)

comment:1 Changed 11 years ago by proasailor

P.S. the problem appears when valid terms contain commas, like this:

Meningitis, Viral

comment:2 Changed 11 years ago by proasailor

a working test case has been submitted to the plugin's author

comment:3 Changed 11 years ago by joern

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.