0

http://jsfiddle.net/Share_Knowledge/dgtqptr7/

I am trying to use autocomplete functionality of jquery ui into my project But i have no idea why THE SECOND $('.search').autocomplete() is not working.

maybe i have to use $.noConflict()

if yes how i can use it $.noConflict()

would any body tell me how to use it to solve this problem out any help please i would be thankful

using firebug i get these errors POST http://localhost/autoservice/public_html/tickets/load_spareparts/11/instance

First i don't what is the word instance coming from..???

here is the order of the js files

-js/jquery-ui.min.js
-jquery.autocomplete.js


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
Share Knowledge
  • 297
  • 3
  • 18
  • See `class` `.search` at "THE SECOND `$('.search').autocomplete()` is not working" , or `id` `#search` at `$('#search').autocomplete()` ? – guest271314 Feb 26 '15 at 17:25
  • $('#search').autocomplete({}) for sure ID not CLASS – Share Knowledge Feb 26 '15 at 17:30
  • See http://stackoverflow.com/questions/17568630/jqueryui-version-1-10-autocomplete-how-to-set-renderitem , http://jqueryui.com/autocomplete/#custom-data – guest271314 Feb 26 '15 at 17:31
  • i have test the second autocomplete (#search).autocompete() on a different project it works perfectly, i have used the jquery ui api documentation. as i said it works on a different project. some how it does not work on this project – Share Knowledge Feb 26 '15 at 17:34
  • Can describe _"it does not work"_ ? – guest271314 Feb 26 '15 at 17:35
  • i mean i am expecting some data to be returned from the server.. when i use fire bug i get this error – Share Knowledge Feb 26 '15 at 17:37
  • POST http://localhost/autoservice/public_html/tickets/load_spareparts/11/instance – Share Knowledge Feb 26 '15 at 17:37
  • See http://api.jqueryui.com/autocomplete/#option-source "For example, if the source option is set to "http://example.com" and the user types foo, a **GET** request would be made to http://example.com?term=foo." , http://stackoverflow.com/questions/21385892/how-to-use-source-function-and-ajax-in-jquery-ui-autocomplete – guest271314 Feb 26 '15 at 17:43
  • i am using the same code on different project..which i am using post request. on this project i am using post request as well, but it's not returning any data from the server..how ever it adds the word instance to the url, and i am wondering why is that... – Share Knowledge Feb 26 '15 at 17:47
  • Try creating stacksnippets http://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/ , jsfiddle http://jsfiddle.net to demonstrate ? – guest271314 Feb 26 '15 at 17:53
  • http://jsfiddle.net/Share_Knowledge/dgtqptr7/ – Share Knowledge Feb 26 '15 at 18:00
  • http://jsfiddle.net/dgtqptr7/1/ – guest271314 Feb 26 '15 at 18:28

0 Answers0