javascript - jQuery autocomplete select first when click outside -


i using autocomplete plugin , want item focused being selected if don't click on it, instead click outside of input field.

$('#adress_input_box').tagsinput({     'width':'500px',     'removewithbackspace': false,     'defaulttext': 'strasse, ort, plz oder gemeinde eingeben',     'placeholdercolor': '#aaacab',     'onremovetag': function(event){           //do stuff here     },     onaddtag: function(e){          //do stuff here     },     interactive: true,     autocomplete_url: '/includes/autocomplete.php',     autocomplete:{         close: function(event, ui){             allowcreatingtag=false;         },         select: function(event, ui){         //stuff                      },         source: function( request, response ) {         $.ajax({           url: "/includes/autocomplete.php",           datatype: "json",           type: "post",           data: {             "term": request.term           },           error: function(){                allowcreatingtag = false;           },           success: function( data ) {               allowcreatingtag=true;             response( $.map( data, function( item ) {               return {                 label: item.label,                 value: item.value,                 category: item.category,               }             }));           }         });       },       minlength: 2,        autofocus: true,     } }); 

i using "tagsinput" plugin, make takes inputs.

here custom autocomplete:

  $.widget( "custom.autocomplete", $.ui.autocomplete, {         _rendermenu: function( ul, items ) {           var = this,             currentcategory = "";           $.each( items, function( index, item ) {             if ( item.category != currentcategory ) {               ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );               currentcategory = item.category;             }             that._renderitemdata( ul, item );           });         }       }); 

you mayadd focus event of autocomplete.

focus: function(event, ui) {     $(".adress_input_box li.result").removeclass("selected");     $("#ui-active-menuitem")         .closest("li")         .addclass("selected"); }, 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -