Recoded how the Auto-complete subdivision search worked in php and js
This commit is contained in:
@@ -7,8 +7,6 @@ $(document).ready(function () {
|
||||
|
||||
var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}");
|
||||
|
||||
// console.log($sessionStorage);
|
||||
|
||||
// =================
|
||||
// Process Enter Key
|
||||
// =================
|
||||
@@ -206,19 +204,45 @@ $(document).ready(function () {
|
||||
|
||||
});
|
||||
|
||||
// ---------------------
|
||||
// Autocomplete Searches
|
||||
// ---------------------
|
||||
|
||||
$(".subdivision-autocomplete").autoComplete({
|
||||
|
||||
resolverSettings: {
|
||||
url: "main.php?Xaction=PermitsBySubdivision.getAutoCompleteSubdivisions",
|
||||
queryKey: "permit_sub_div_name",
|
||||
requestThrottling: 0
|
||||
},
|
||||
noResultsText: "No Matching Subdivisions Found.",
|
||||
bootstrapVersion: "4"
|
||||
// ====================
|
||||
// Autocomplete Searchs
|
||||
// ====================
|
||||
|
||||
let subdivisionSearchTimer = null;
|
||||
|
||||
$(".subdivision-autocomplete").on("keyup", function () {
|
||||
|
||||
clearTimeout(subdivisionSearchTimer);
|
||||
|
||||
let $input = $(this);
|
||||
let searchValue = $input.val().trim();
|
||||
|
||||
// optional: don't search until 2+ chars
|
||||
if (searchValue.length < 2) {
|
||||
$(".subdivision-results").empty().hide();
|
||||
return;
|
||||
}
|
||||
|
||||
subdivisionSearchTimer = setTimeout(function () {
|
||||
|
||||
$.ajax({
|
||||
url: "main.php",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
data: {
|
||||
Xaction: "PermitsBySubdivision.getAutoCompleteSubdivisions",
|
||||
subscription_serial: $sessionStorage.subscription_serial,
|
||||
permit_sub_div_name: searchValue
|
||||
},
|
||||
success: function (results) {
|
||||
renderSubdivisionResults(results, $input);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}, 250);
|
||||
|
||||
});
|
||||
|
||||
@@ -775,4 +799,36 @@ function getPermitRecordDialog(permit_serial) {
|
||||
|
||||
return dialog;
|
||||
|
||||
}
|
||||
|
||||
function renderSubdivisionResults(results, $input) {
|
||||
|
||||
let $dropdown = $(".subdivision-results");
|
||||
|
||||
if (!$dropdown.length) {
|
||||
$dropdown = $("<div class='subdivision-results dropdown-menu show w-100'></div>");
|
||||
$input.closest(".subdivision-wrapper").append($dropdown);
|
||||
}
|
||||
|
||||
$dropdown.empty();
|
||||
|
||||
if (!results.length) {
|
||||
$dropdown.append("<span class='dropdown-item text-muted'>No Matching Subdivisions Found</span>");
|
||||
return;
|
||||
}
|
||||
|
||||
results.forEach(function (item) {
|
||||
|
||||
let $option = $("<button type='button' class='dropdown-item'></button>").text(item);
|
||||
|
||||
$option.on("click", function () {
|
||||
$input.val(item);
|
||||
$dropdown.hide();
|
||||
});
|
||||
|
||||
$dropdown.append($option);
|
||||
|
||||
});
|
||||
|
||||
$dropdown.show();
|
||||
}
|
||||
Reference in New Issue
Block a user