autocomplete: how do I avoid a duplicate search?
I use autocomplete as a kind of dataset chooser. If the user chooses a value from the autocomplete lookup, the database is queried for the matching dataset. If the user types in a new value, the user can enter a new dataset. An issue arises when the user types in an existing value rather than choosing it from the autocomplete suggestion list. When this is done, the autocomplete .result() method is not called and no dataset is retrieved. To fix this I added a `
.blur(
function
(){$(
this
).search();});` to the input element. This fixed the original problem.
Now I have the problem that .result() fires on selection of suggestion AND on blur. I would like .result() to fire on selection of suggestion OR on blur. How do I make that happen?
Here is my code:
- $('#groupset').autocomplete('ajax/php/leeruns.php');
- $(
'#groupset').result( function
(event, data, formatted) {
if
(data){ $(
'#groupsetdesc'
).val(formatted); }
else
{ $(
'#groupsetdesc'
).val(
''
); } } ).blur(
function
(){$(
this
).search();});
Sorry for the code format. This WYSIWYG isn't.