Md. Sahadat Hossain
Md. Sahadat Hossain

Reputation: 3236

How to add a custom new option in onkeyup event in jquery autocomplete

Let I search hello world in a jquery autocomplete implemented textbox. My system has this keyword so autocomplete show this keyword as suggestion, but I want to add a new option hello world.

Please, see the picture bellow to understand what I want. enter image description here

Upvotes: 1

Views: 269

Answers (1)

artm
artm

Reputation: 8584

See http://jsfiddle.net/01rbk4cx/

You can use response which is run after the search is finished and before the selection is shown; http://api.jqueryui.com/autocomplete/#event-response

Just use the callback and add your input's value to the search result:

$( "#tags" ).autocomplete({
     source: availableTags,
     response: function(e, ui){
         ui.content.push({ label: $("#tags").val(), 
                           value: $("#tags").val()});
     }
})

Upvotes: 3

Related Questions