Skip to content

Commit

Permalink
Ajax parts filter
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisi authored and chrisi committed Apr 27, 2023
1 parent 34c37a4 commit d990253
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions pages/inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<div class="row">
<div class="col-3">
<form method="get" id="search_form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input type="text" class="form-control form-control-sm" id="search" name="search" placeholder="Search parts..."
<input type="text" class="form-control form-control-sm" id="search" name="search" placeholder="Filter parts..."
value="<?php echo htmlspecialchars($search_term); ?>"><br><br><br>
<input type="text" class="form-control" id="filter" placeholder="Filter results on this page...">
<!-- <input type="text" class="form-control" id="filter" placeholder="Filter results on this page..."> -->
</div>
<div class="col-3">
<input type="hidden" name="cat[]" id="selected-categories" value="">
Expand All @@ -57,7 +57,8 @@
</div>
<div class="col-1">
<button type="submit" class="btn btn-sm btn-primary" name="apply">Search</button><br><br>
<button type="button" class="btn btn-sm btn-outline-primary" onclick='callPartEntryModal(<?php echo json_encode($locations); ?>);'>Enter New</button>
<button type="button" class="btn btn-sm btn-outline-primary"
onclick='callPartEntryModal(<?php echo json_encode($locations); ?>);'>Enter New</button>
</div>
<div class="col-1">
<?php echo "Results per page:"; ?>
Expand Down Expand Up @@ -150,26 +151,27 @@
focusStockChangeQuantity();
focusNewPartName();

$('#search').on("keyup input", function(){
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if(inputVal.length){
$.get("../includes/buildPartsTable.php", {term: inputVal}).done(function(data){
// Display the returned data in browser
// resultDropdown.html(data);
var querystring = "?search=" + inputVal;
rebuildPartsTable(querystring);
});
} else{
resultDropdown.empty();
}
// Experimental ajax search
$('#search').on("keyup input", function () {
/* Get input value on change */
var inputVal = $(this).val();
var resultDropdown = $(this).siblings(".result");
if (inputVal.length) {
$.get("../includes/buildPartsTable.php", { term: inputVal }).done(function (data) {
// Display the returned data in browser
// resultDropdown.html(data);
var querystring = "?search=" + inputVal;
rebuildPartsTable(querystring);
});
} else {
resultDropdown.empty();
}
});

// Set search input value on click of result item
$(document).on("click", ".result p", function(){
$(this).parents(".search-box").find('input[type="text"]').val($(this).text());
$(this).parent(".result").empty();
$(document).on("click", ".result p", function () {
$(this).parents(".search-box").find('input[type="text"]').val($(this).text());
$(this).parent(".result").empty();
});

});
Expand Down

0 comments on commit d990253

Please sign in to comment.