javascript - JQuery Autocomplete issue - each character on separate line -


i trying autocomplete text box working. here code have far:

if ($action == 'find_products') {     $dept = $_post['dept'];      $stk_adddep = "         select * stocktake_products stocktake_id = '{$stocktake_id}' , is_deli = 0 , department_description '{$dept}%' limit 10; ";       $result = db::c()->query($stk_adddep);      while ($row = $result->fetch(pdo::fetch_assoc)) {    $data[] = array(         'full_name' => $row['product_name'],         'value' => $row['product_name']); }     echo json_encode($data);     die(); } 

div display text box:

<input type="text" placeholder="name" id="customerautocomplte" /> 

js code:

$('#customerautocomplte').autocomplete({              source: function( request, response ) {             var dept = $('#customerautocomplte').val();         $.ajax({             url: '<?php echo navigation::gurl('/users/admin/stocktake_details_nonbcodeditems.php', array('stocktake_id' => $stocktake_id, 'action' => 'find_products'));?>',             type: 'post',             data: {'dept':dept},                          success: function( data ) {                          response( $.map( data, function( item ) {                             return {                                 label: item,                                 value: item                             }                         }));                     }                 });             },             autofocus: true,             minlength: 0                   }); 

php part seems working fine, response follows:

[{"full_name":"prince hubert cristal","value":"prince hubert cristal"},{"full_name":"schloer","value" :"schloer"},{"full_name":"underberg 20ml","value":"underberg 20ml"},{"full_name":"odessa vodka 20cl" ,"value":"odessa vodka 20cl"},{"full_name":"marula","value":"marula"},{"full_name":"maderia verdelho 15yr old","value":"maderia verdelho 15yr old"},{"full_name":"madeira malsmey 15yr old","value":"madeira malsmey 15yr old"},{"full_name":"hennessey 5cl","value":"hennessey 5cl"},{"full_name":"jack daniels 35cl","value":"jack daniels 35cl"},{"full_name":"madeira bual 10 yr old","value":"madeira bual 10 yr old"}]

however, way results displayed in text box incorrect. gets displayed whole line "value":"jack daniels 35cl" example each character being separate entry in text box.

any appreciated. thanks!

try use item.value in callback function:

label: item.value value: item.value

$('#customerautocomplte').autocomplete({          source: function( request, response ) {         var dept = $('#customerautocomplte').val();     $.ajax({         url: '<?php echo navigation::gurl('/users/admin/stocktake_details_nonbcodeditems.php', array('stocktake_id' => $stocktake_id, 'action' => 'find_products'));?>',         type: 'post',         data: {'dept':dept},                      success: function( data ) {                      response( $.map( data, function( item ) {                         return {                             label: item.value,                             value: item.value                         }                     }));                 }             });         },         autofocus: true,         minlength: 0               }); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -