function patron_autocomplete(params) { var patron_container = params.patron_container; var input_autocomplete = params.input_autocomplete; var patron_input_name = params.patron_input_name || 'cardnumber'; var field_to_retrieve = params.field_to_retrieve || 'cardnumber'; $( input_autocomplete ).autocomplete({ source: "/api/v1/patrons", minLength: 3, select: function( event, ui ) { var field = ui.item.cardnumber; if ( field_to_retrieve == 'borrowernumber' ) { field = ui.item.borrowernumber; } AddPatron( ui.item.firstname + " " + ui.item.middle_name + " " + ui.item.surname, field, patron_container, patron_input_name ); input_autocomplete.val('').focus(); return false; } }) .data( "ui-autocomplete" )._renderItem = function( ul, item ) { return $( "
" ) .data( "ui-autocomplete-item", item ) .append( "" + item.surname + ", " + item.firstname + " " + item.middle_name + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) .appendTo( ul ); }; $("body").on("click",".removePatron",function(e){ e.preventDefault(); var divid = $(this).parent().attr("id"); var cardnumber = divid.replace("borrower_",""); RemovePatron(cardnumber, patron_container); }); } function AddPatron( patron_name, value, container, input_name ) { div = "