Cleaning up type ahead

This commit is contained in:
Brian McGonagill 2024-07-07 18:59:40 -05:00
parent cba5026ee4
commit dbd945391d
4 changed files with 11 additions and 14 deletions

View file

@ -20,7 +20,7 @@
<i class="material-icons clickable" id="filterOff">clear</i> <i class="material-icons clickable" id="filterOff">clear</i>
{{/if}} {{/if}}
</div> </div>
<div class="col s10 m11 l11"> <div class="col s4 m3 l3">
Filter LIst Filter LIst
</div> </div>
</div> </div>
@ -35,11 +35,11 @@
</div> </div>
{{else}} {{else}}
<div class="row"> <div class="row">
<div class="col s9 m10 l10 input-field"> <div class="col s8 m9 l10 input-field">
<input type="text" class="autocomplete" id="findListItems" /> <input type="text" class="autocomplete" id="findListItems" autocomplete="off" />
<label for="findListItems">Item...</label> <label for="findListItems">Item...</label>
</div> </div>
<div class="col s3 m2 l2"> <div class="col s4 m3 l2">
<a class="waves-effect waves-light btn saveListItem green right">Add</a> <a class="waves-effect waves-light btn saveListItem green right">Add</a>
</div> </div>
</div> </div>

View file

@ -19,6 +19,7 @@ Template.listItemsForm.onRendered(function() {
Session.set("itemReqErr", false); Session.set("itemReqErr", false);
Session.set("showReceivedItems", false); Session.set("showReceivedItems", false);
Session.set("filtering", false); Session.set("filtering", false);
Session.set("findListItems", {});
this.autorun(() => { this.autorun(() => {
$('input.autocomplete').autocomplete({ $('input.autocomplete').autocomplete({
data: Session.get("findListItems"), data: Session.get("findListItems"),
@ -96,17 +97,21 @@ Template.listItemsForm.events({
if (event.which !== 13) { if (event.which !== 13) {
let listItemObj = {}; let listItemObj = {};
let findItemVal = $("#findListItems").val(); let findItemVal = $("#findListItems").val();
console.log("Should start showing options now...");
Session.set("listItemVal", findItemVal); Session.set("listItemVal", findItemVal);
let listItemInfo = Products.find({ prodName: {$regex: findItemVal + '.*', $options: 'i'}}, { limit: 5 }).fetch(); let listItemInfo = Products.find({ prodName: {$regex: findItemVal + '.*', $options: 'i'}}, { limit: 5 }).fetch();
if (typeof listItemInfo != 'undefined' && listItemInfo != "" && listItemInfo != null) { if (typeof listItemInfo != 'undefined' && listItemInfo != "" && listItemInfo != null) {
// console.log(" listItemInfo: ");
// console.dir(listItemInfo);
for (i=0; i < listItemInfo.length; i++) { for (i=0; i < listItemInfo.length; i++) {
let item = listItemInfo[i].prodName; let item = listItemInfo[i].prodName;
let store = listItemInfo[i].prodStore; let store = listItemInfo[i].prodStore;
listItemObj[item] = store; listItemObj[item] = store;
} }
}
Session.set("findListItems", listItemObj); Session.set("findListItems", listItemObj);
} }
}
}, },
'click #filterOn' (event) { 'click #filterOn' (event) {
event.preventDefault(); event.preventDefault();

View file

@ -25,7 +25,7 @@ Template.listsTbl.events({
if (listId == "addList") { if (listId == "addList") {
$('#modalList').modal('open'); $('#modalList').modal('open');
} else { } else {
console.log("listId is: " + listId); // console.log("listId is: " + listId);
Session.set("listId", listId); Session.set("listId", listId);
Meteor.setTimeout(function() { Meteor.setTimeout(function() {
FlowRouter.go('/listitems'); FlowRouter.go('/listitems');

View file

@ -37,14 +37,6 @@ Meteor.publish("myProducts", function() {
} }
}); });
Meteor.publish("listProducts", function(itemNameListing) {
try {
return Products.find({ itemName: {$regex: itemNameListing + '.*', $options: 'i'}}, { limit: 5 });
} catch (error) {
console.log(" ERROR pulling items by filtered item name: " + error);
}
});
Meteor.publish("myLists", function() { Meteor.publish("myLists", function() {
try { try {
return Lists.find( { $or: [ { listOwner: this.userId, listComplete: false }, { listShared: true, listComplete: false } ] } ); return Lists.find( { $or: [ { listOwner: this.userId, listComplete: false }, { listShared: true, listComplete: false } ] } );