Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear text box in Jquery Autocomplete after selection

I want to clear the textbox having Jquery Autocomplete once the user has made the selection.

I tried to clear the field by :

select: function(event, ui) {    $(this).val(''); } 

But this is not working.I am using jquery-1.6.4 and jquery-ui-1.8.16.

Any Ideas?

like image 803
user1163513 Avatar asked Jul 23 '12 07:07

user1163513


People also ask

How do I delete an autocomplete text box?

addClass("ui-screen-hidden"); which will hide all the autocomplete filtered list upon selecting it.

How pass multiple parameters in jQuery autocomplete?

In that case, you need to define a callback function to the source option of autoComplete call. Also, you can pass multiple parameters using this approach. Your jQuery UI Autocomplete function would be like the following. In the source file, you can get the term and additional parameters using the $_GET variable.

How does autocomplete work in jQuery?

In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.


1 Answers

The select event occurs before the field is updated. You will have to cancel the event to avoid the field being updated after you have cleared it:

select: function(event, ui) {     $(this).val("");     return false; } 

Update: As T.J. pointed out below, it's slightly faster to update the value DOM property directly instead of going through val():

select: function(event, ui) {     this.value = "";     return false; } 
like image 71
Frédéric Hamidi Avatar answered Nov 11 '22 12:11

Frédéric Hamidi