Added autocomplete to Menu Item entryies

This commit is contained in:
Brian McGonagill 2024-07-29 07:46:30 -05:00
parent 9abb198e82
commit d8c08578f3
4 changed files with 42 additions and 7 deletions

View file

@ -5,7 +5,7 @@ import { M } from '../lib/assets/materialize.js';
Template.menuItemsForm.onCreated(function() {
this.subscribe("myMenus");
this.subscribe("myMenuItems", Session.get("menuId"));
this.subscribe("allMenuItems", Session.get("menuId"));
});
Template.menuItemsForm.onRendered(function() {
@ -13,6 +13,15 @@ Template.menuItemsForm.onRendered(function() {
var instances = M.Datepicker.init(elems, {});
Session.set("menuItemErr", false);
Session.set("menuListItems", {});
this.autorun(() => {
var elema = document.querySelectorAll('.autocomplete');
var instancea = M.Autocomplete.init(elema, {
minlength: 0,
data: Session.get("menuListItems"),
});
});
});
Template.menuItemsForm.helpers({
@ -65,5 +74,20 @@ Template.menuItemsForm.events({
}
});
}
}
});
},
'keyup #menuItemInp' (event) {
if (event.which != 13) {
let findMenuItem = $("#menuItemInp").val();
let menuItemInfo = MenuItems.find({ itemName: {$regex: findMenuItem + '.*', $options: 'i' }}).fetch();
if (typeof menuItemInfo != 'undefined' && menuItemInfo != '' && menuItemInfo != null) {
getMenuItemList(menuItemInfo);
}
}
},
});
getMenuItemList = function(menuItemInfo) {
let menuItemObjArray = [];
menuItemObjArray = menuItemInfo.map(info => ({ id: info._id, text: info.itemName }));
Session.set("menuListItems", menuItemObjArray);
}