JSFiddle - React, Tailwind, and code Playground

by Share Knowledge

HTML

<input type="text" id="search" class="form-control">
    
<form action="post" action="" id="spareParts" class="">
                   
 <table class="table" id="addSpareParts">
                            <thead>
                            <tr>
                                <th>Item Code</th>
                                <th>Item Name</th>
                                <th>Item Price</th>
                                <th>Item Qty</th>
                                <th>Item Description</th>
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody class="inject">
                                
                            </tbody>
                        </table>
</form>

JavaScript

jQuery(document).ready(function($) {

$.ajaxSetup( { type: "post" } );

// THIS IS WORKING PERFECTLY 
    $("#item").autocomplete(url+'/item_search', {
        minChars:0,
        selectFirst: false,
        width: 749,
        multiple: false,
        matchContains: true,
        formatItem: formatItem,
        formatResult: formatResult
    });

// THIS SHOW THE ERROR WHICH MENTIONED UP THERE
// IT'S NOT WORKING    
$('#search').autocomplete({
        minLength: 0,
        source: path3+'/get_spareparts',
        focus: function( event, ui) {
            $('#search').val( ui.item.item_id );
            return false;
        },
        select: function(event, ui) {
            output   = '';
            output  += '<tr>';
            output  += '<td>'+ui.item.item_id+'</td>';
            output  += '<input type="hidden" value="'+ui.item.id+'" name="item_id"></td>';
            output  += '<td>'+ui.item.item_name+'</td>';
            output  += '<td>'+ui.item.price+'</td>';
            output  += '<td><input type="text" name="qty" value="" size="1" class="qty"></td>';
            output  += '<td>'+ui.item.desc+'</td>';
            output  += '<td><a href="" class="spareTrash" data-toggle="button">Delete</a></td>';
            output  += '</tr>';

            $('.inject').append(output);
            $(this).val('');
            deleteItem(); // DELETE ITEM
            return false;
        }

    }) .autocomplete( "instance" )._renderItem = function( ul, item ) {
        return $( "<li>" )
        .append( "<a>" + item.desc + "<br>" + item.item_id + "</a>" )
        .appendTo( ul );
    };


function deleteItem () {
        $('.spareTrash').on('click', function(event) {
            event.preventDefault();
   $(this).parent().parent().fadeOut(900, function(){  $(this).remove();});
        });
}


}); // END READY JQUERY