add autocomplete filtering on label AND value

as it is, trying to filter by the items in the array is frustrating as only the value is filtered on. this change allows for filtering on both.
This commit is contained in:
Kyle J. Kemp 2022-06-10 10:07:19 -05:00 committed by GitHub
parent 1d8871d5e5
commit 9b753303df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,13 @@
{{ $currentNode := . }} {{ $currentNode.Scratch.Set "pages" .Site.Pages
}} {{ $pages := ($currentNode.Scratch.Get "pages") }}
<script>
$.ui.autocomplete.filter = function (array, term) {
var matcher = new RegExp('(^| )' + $.ui.autocomplete.escapeRegex(term), 'i');
return $.grep(array, function (value) {
return matcher.test(value.label) || matcher.test(value.value) || matcher.test(value);
});
};
$(function() {
var projects = [
{{ range $pages }}