Last active
May 6, 2021 01:58
-
-
Save ZhenDeng/1b4293a62d6f166d7defd831b2aae0a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.showPostcodeAutoComplete = function (pcode) { | |
console.log(pcode); | |
$(this).autocomplete({ | |
source: function (request, response) { | |
$.ajax({ | |
url: 'api/checkout/GetPostCodeList', | |
type: 'POST', | |
contentType: 'application/json; charset=utf-8', | |
data: JSON.stringify(pcode), | |
dataType: 'json', | |
asyn: false, | |
success: function (output) { | |
console.log(output); | |
response($.map(output, function (item) { | |
var displayLabel; | |
if (item === "No match found") | |
displayLabel = "No match found"; | |
else { | |
if (item.companyCode === '1') { | |
displayLabel = item.suburb + ", " + item.state + ", " + item.postcode; | |
} | |
else { | |
displayLabel = item.suburb + ", " + item.postcode; | |
} | |
} | |
return { | |
suburb: item.suburb, | |
state: item.state, | |
postcode: item.postcode, | |
label: displayLabel | |
}; | |
}) | |
); | |
} // end success | |
}); // end ajax | |
}, | |
minLength: 2, | |
delay: 0, | |
autoFocus: true, | |
select: function (event, ui) { | |
ui.item.value = ui.item.postcode; | |
$('#suburbField').val(ui.item.suburb); | |
$('#stateField_Input').val(ui.item.state); | |
$('#stateField').val(ui.item.state); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment