Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$.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
You can’t perform that action at this time.