From 150cbc7079a8a850abca3200a7cd25aad9e6fec3 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 16 Mar 2010 14:51:08 +1100 Subject: [PATCH] Tweaked the customer similar JS. Now only fires if 3 chars entered --- webroot/js/autocomplete-customer.js | 55 ++++++++++++++++------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/webroot/js/autocomplete-customer.js b/webroot/js/autocomplete-customer.js index 89294a19..f0019eaf 100644 --- a/webroot/js/autocomplete-customer.js +++ b/webroot/js/autocomplete-customer.js @@ -9,37 +9,44 @@ $(function() { - $("#dialog").hide(); - $("#customerName").change(function () { + $("#dialog").hide(); - $("#dialog").dialog('close'); //Remove any previously opened dialogs + /*If the user has entered 3 or more characters. Check to see if its similar to existing customers. */ + $("#customerName").change(function () { + + if($("#customerName").val().length >= 3) { + + $.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) { + $("#similarCustList").html(data); + }); + + + $("#dialog").dialog({ + position: 'right', + width: 400 + }); - $.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) { - $("#similarCustList").html(data); - }); - - - $("#dialog").dialog({position: 'right', width: 400}); + } - }), + }), - $("#CustomerCountryName").autocomplete({ - source: "/countries/completeCountry", - minLength: 3, - select: function(event, ui) { - //alert("You selected " + ui.item.value + " ID:"+ ui.item.id); - $("#CustomerCountryId").val(ui.item.id); + $("#CustomerCountryName").autocomplete({ + source: "/countries/completeCountry", + minLength: 3, + select: function(event, ui) { + //alert("You selected " + ui.item.value + " ID:"+ ui.item.id); + $("#CustomerCountryId").val(ui.item.id); - if(ui.item.value == 'Australia') { - $("#ABN").show(); - } - else { - $("#ABN").hide(); - } - } - }); + if(ui.item.value == 'Australia') { + $("#ABN").show(); + } + else { + $("#ABN").hide(); + } + } + });