Reputation: 12189
Why won't #input-myBox
clear when I select an item? It seems autocomplete is preventing my .val('')
to work so how can I workaround this?
$("#input-myBox").autocomplete({
source: response,
minLength: 1,
select: function(event, ui) {
var selectedObj = ui.item;
$("#input-myBox").appendTo(".foo");
$("#input-myBox").val('');
}
});
Upvotes: 19
Views: 29499
Reputation: 7228
If you just want to substitute the selected value for something else:
select: function( event, ui ) {
ui.item.value = substituteWord(ui.item.value);
}
Upvotes: 4
Reputation: 1351
Also, you can use 'return false;' to stop autocomplete setting the field.
select: function (event, ui) {
var selectedObj = ui.item;
$("#input-myBox").appendTo(".foo");
$("#input-myBox").val('');
return false;
}
Upvotes: 9
Reputation: 12189
event.preventDefault()
stops autocomplete setting the field.
select: function (event, ui) {
event.preventDefault();
var selectedObj = ui.item;
$("#input-myBox").appendTo(".foo");
$("#input-myBox").val('');
}
Upvotes: 49
Reputation: 150293
There is inconsistent with your code:
$("#input-mybox").appendTo(".foo");
$("#input-myBox").val('');
"#input-myBox" || "#input-mybox" ???
Upvotes: 0
Reputation: 4048
Is it #input-mybox
(lowercase b) or #input-myBox
(uppercase b) ?
This might be your problem :)
Edit: rob beat me to it
Upvotes: 1