Closed whatcoloris closed 5 years ago
so, this seems to work much better:
var initAutocomplete = function(){
var dataObj = {};
var hrefObj = {};
for(var proj of data){
if(proj.title != ''){
var _key = proj.title;
if(proj.contributor && proj.contributor !== ''){
_key = _key + ' -- ' + proj.contributor;
}
if(proj.place && proj.place !== ''){
_key = _key + ' -- ' + proj.place;
}
dataObj[_key.trim()] = null;
hrefObj[_key.trim()] = proj.url;
}
}
M.Autocomplete.init(document.querySelectorAll('input.autocomplete'), {
data: dataObj,
limit: 50,
onAutocomplete: function(val) {
var projKey = Object.keys(hrefObj).filter(function(i){return i === val})[0]
if(projKey && hrefObj[projKey]){
window.location = hrefObj[projKey];
}
},
minLength: 1
});
}
@whatcoloris i just pushed a fix to master
cleaned it - still sure there's a more graceful method....