$(document).ready(function(){ locoList = getLocoList(); savedMaps = getPreparedMaps(); $("#loco-form").on("submit", function (e) { e.preventDefault(); data = $(this).serializeArray(); mode = $("#loco-submit").attr("loco-mode"); if(mode != 'edit'){ saveLocomotive(data); }else{ id = $("#loco-submit").attr("loco-id") saveEditedLocomotive(data, id); } locoList = getLocoList(); loadLocomotives(); $("#loco-form")[0].reset(); $("#loco-form-content").css("display", "none"); }); $("#add-loco").on("click", function () { savedMaps = getPreparedMaps(); $("#loco-form")[0].reset(); $("#loco-form-content").css("display", "inline-block"); $(".add-loco-form .add-loco-head").html("Add Locomotive"); $("#loco-submit").attr("loco-mode", "add"); }); $("#close-addloco-model").on("click", function () { if ($("#loco-form-content").is(":visible")) { $("#loco-form-content").css("display", "none"); } }); $("#ex-locoid").autocomplete({ delay: 0, minLength: 0, source: function (request, response) { var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); response( $.grep(locoList, function (item) { if (item != undefined) { console.log(item); return ( matcher.test(item.name) || matcher.test(item.cv) || matcher.test(item.type) || matcher.test(item.manufacturer) ); } else { return true; } }) ); }, select: function (event, ui) { $(this).val(ui.item.cv + " | " + ui.item.name); $(this).attr("loco-cv", ui.item.cv); return false; }, }) .focus(function () { console.log("Focused"); $(this).autocomplete("search", ""); }) .data("ui-autocomplete")._renderItem = function (ul, item) { $(ul).addClass("res-list"); return $("
") .data("item.autocomplete", item) .append( "" + item.name + "
CV:" + item.cv + "|" + item.type + "|" + item.brand + "" + item.mname + "