I followed the documentation from the user interface site and looked at a number of tutorials and got my code like work, it is ajax in the list of terms that I want, and you can choose one and it puts the value, and then ",". However, after that, it does not request the second value again.
Also, when I enter partial text and say that 10 entries appear, tabbing just moves on to the next form field, not sure what happened to my .bind, maybe with the setting? If someone does not mind taking a look, it will be very grateful!
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
jQuery('#tagSearch')
.bind('keydown', function(event) {
if (event.keyCode === jQuery.ui.keyCode.TAB &&
jQuery(this).data('autocomplete').menu.active) {
event.preventDefault();
}
})
.autocomplete({
autoFocus: true,
source: function(request, add) {
console.log('source');
jQuery.getJSON('/get-tags-like.php?term_start=' + request.term, function(response) {
var possibleTerms = [];
jQuery.each(response, function(i, val) {
possibleTerms.push(val.name + ' ' + '(' + val.count + ')');
});
add(jQuery.map(possibleTerms, function(item) {
console.log(possibleTerms);
return item;
}));
});
},
focus: function() {
console.log('focus');
return false;
},
select: function(event, ui) {
console.log('select');
var terms = split(this.value);
terms.pop();
terms.push(ui.item.value);
terms.push('');
this.value = terms.join(',');
var currentVal = this.value;
currentVal = currentVal.replace(/\s\(.\)/, '');
this.value = currentVal;
return false;
},
minLength: 2
});
source
share