Home > Blockchain >  How to set input field to empty which is used as autocomplete in jquery?
How to set input field to empty which is used as autocomplete in jquery?

Time:05-28

I am an input field that I am using for autocomplete so after selecting an option I want to clear that input field that is used as a autocomplete. bellow is my example but it's not working. $('#autocomplete').val('') is doing nothing.

$('#autocomplete').autocomplete({
    source: my_url,
    select: function ( event, ui){
        $('#autocomplete').val('')
    }
})

CodePudding user response:

You can use a timer to ensure the code inside run at the end.

$('#autocomplete').autocomplete({
      source: my_url,
      select: function ( event, ui){
         setTimeout(() => {
              $('#autocomplete').val("");
            }, 1);
      }
   }
)
  • Related